469,328 Members | 1,247 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,328 developers. It's quick & easy.

Passing variable to ASP with 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.

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>
Jul 20 '05 #1
7 3349
Dave A wrote:
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?
Jul 20 '05 #2
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
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>
=========================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #6
Dave Anderson wrote:
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
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


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

Brian
Jul 20 '05 #7
'<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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by domeceo | last post: by
2 posts views Thread by RootShell | last post: by
1 post views Thread by cirillo_curiosone | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.