Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a script / document value ?

Status
Not open for further replies.

mjhaston

Programmer
Oct 9, 2006
5
US
I have this script that works great at toggling my search filters while on the page. I have a 3 page application that I would like to send this value from one page to another.

If I call my variable "show". How would I grab the value of display and pass it to the next page?

Sorry if this is a beginner question. I pass parms from forms and in the url all over the place. Never done it from a document or script value yet.

Thanks in advance.




<script type="text/javascript">
<!--
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}
 
Just make a hidden input field, such as this if "block" is the default value or some other initial value as picked up server-side.
[tt]
<input type="hidden" name="show" id="x" value="block" />
[/tt]
Then whenever client-side changes it via the function, add the line to change that info which now stands ready to be passed to next page.
[tt]
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
document.getElementById("x").value=e.style.display;
}
[/tt]
 
Thanks for the code. I think I might have an issue because to get to the next page I'm going by way of link and not a submit.

Thanks for the quick reply.
 
there are two methods you might consider:

storing the variable value in a cookie, then reading the value from the cookie on the ensuing page;
passing the value in the querystring, then determining the value on the ensuing page by parsing the querystring.

without you providing more information, there's little else we can tell you.

why did you post that function?



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Let me show, instead of style.display, an input textbox with name=show. Upon changing it, the value will be reflect into the hyperlink.
[tt]
<html>
<head>
<script language="javascript">
function doit(obj) {
var oelem=document.getElementById("lnk00");
var shref=oelem.href;
if (shref.indexOf(obj.name+"=")!=-1) {
var rx=new RegExp(obj.name+"=.*?(&|$)");
shref=shref.replace(rx,obj.name+"="+escape(obj.value.replace(/(^\s+|\s+$)/g,""))+"$1");
} else {
shref+="&"+obj.name+"="+escape(obj.value.replace(/(^\s+|\s+$)/g,""));
}
oelem.href=shref;
alert(oelem.href);
}
</script>
</head>
<body>
<form name="formname" action="" onsubmit="return false">
show (block/none?): <input type="text" name="show" onblur="doit(this)" />
</form>
<br />
<a href=" id="lnk00">clickme</a><br />
</body>
</html>
[/tt]
The address bar shows what you have entered as "show" setting.
 
I showed that function to show what I was working with. Once the reply came, I realized that I wasn't working with a form submission.

This is a CGI application on the AS/400 (IBM iSeries). I do have forms in my application, actually two of them. They submit the searches and filters. To navigate from screen to screen I build a parm list and attach it to my url.

Thank you all for your replies. My JavaScripting comes through forums like this or Dreamweaver. Modifying the script is where I run into issues!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top