Passing variable to ASP with javascript

D

Dave A

I have two events in a form that I am passing. One is to a javascript
function, the other is to the same .asp page only with another action
to show different data.

Onchange is calls the function updateclasses, which in turn reloads
another drop-down list. It also reloads the .asp page, which
refreshes the data. My problem is that it refreshes the second
drop-down briefly, until the page reloads, but then resets the form.
How do i pass this data to the .asp?

I thought in the .asp, I could just do something simple like the
following, but wasn't sure of the correct syntax. is there a better
way?

view = request.querystring("view")
if view = "" then
view = "SciLink"
else
%>
<script language="JavaScript">
updateclasses(form1, 0, Student)
</script>
<%
end if



<form name=form1 method=post>
<td><span class=middleColContentBold>SORT BY:</span><br>
<select multiple class="rubricContent"
onchange="gotosite(this.options
[this.selectedIndex].value);updateclasses(this.form, 0,
this.selectedIndex)" style="background-color:FFFFFF; border:1 solid
black; width:110;">
<option value="gradebook3.asp?view=SciLink" <% if view = "SciLink"
then response.write "selected" end if %>>SCILINKS</option>
<option value="gradebook3.asp?view=Student" <% if view = "Student"
then response.write "selected" end if %>>CLASSES</option>
</select>
</td>
</form>
 
D

DB McGee

Dave said:
I have two events in a form that I am passing. One is to a javascript
function, the other is to the same .asp page only with another action
to show different data.

Onchange is calls the function updateclasses, which in turn reloads
another drop-down list. It also reloads the .asp page, which
refreshes the data. My problem is that it refreshes the second
drop-down briefly, until the page reloads, but then resets the form.
How do i pass this data to the .asp?

Why not have the Javascript write the data to a hidden form field(s) then grab
the POST'ed value in the ASP code?
 
D

Dave Anderson

Well, that makes sense. I'm new to javascript. How do you write to a
hidden field?

Where do I put it so the onchange still occurs?

Thanks again

Dave
 
E

Evertjan.

Dave A wrote on 20 jan 2004 in comp.lang.javascript:
I have two events in a form that I am passing. One is to a javascript
function, the other is to the same .asp page only with another action
to show different data.

ASP can be written in javascript, so that would be implicit.
ASP does not equal vbscript, that can be clientside too [in IE]

Do you want to send a clientside value to serverside?

============= test.asp ===============

The value sent to serverside was:
<% = request.form("x") %>

<form method=post id="y">
<input type=hidden id="x" name="x">
</form>

<script>
function z(val){
document.getElementById("x").value = val;
document.getElementById("y").submit();
}
</script>

<button onclick="z('3.14')">3.14</button>
<button onclick="z('Hi')">Hi</button>
<button onclick="z('Bye')">Bye</button>


=========================================
 
D

Dave Anderson

On submitting the form, I am currently doing two things.

Attempting to update a second selection box with the following function
updateclasses(this.form, 0,this.selectedIndex)"
I am also send the form to the .asp page with
onchange="gotosite(this.options this.selectedIndex].value);

<form name=form1 method=post>

Currently, I am doing both of these in the onchange event. If I pass it
to a hidden field, a request it on the page load, what do I put in the
hidden field?

<input type="hidden" name="test" value="updateclasses(this.form,
0,this.selectedIndex)"">

Thanks
 
E

Evertjan.

Dave Anderson wrote on 20 jan 2004 in comp.lang.javascript:
<input type="hidden" name="test" value="updateclasses(this.form,
0,this.selectedIndex)"">

You cannot code-"run" an html value

Please explain what you are doing serverside and what clientside, primarily
to yourself and also to us. I suspect you are mixing both.
 
B

Brian Genisio

Dave said:
Well, that makes sense. I'm new to javascript. How do you write to a
hidden field?

Where do I put it so the onchange still occurs?

Thanks again

Dave

Put this inside a form, and replace the name and value values:
<input type=hidden name=some_name value=some_value>

Brian
 
D

Dave Anderson

'<input type=hidden name=some_name value=some_value>
'

This I completely understand. What I don't understand, due to my lack of
knowledge with javascript is what are those values? Currently, I am
calling this function with an onchange event. How do I know what the
function is passing?

updateclasses(this.form, 0, this.selectedIndex)

I assume this.form would be my form name form1
What is this.selectedIndex? The values of my options or their names?

Also, once I request the variable, I assume I can just recall the
function after the page loads?

I apreciate everyone's patience and help with this. I may just be
confusing the issue!

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top