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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hidden fields

Status
Not open for further replies.

zekmek

Programmer
Jun 12, 2003
44
0
0
PT
Hello everybody,

Here is my question. i have a page in which i have 3 images with 1 link on each one of them. the link points on the same page. I would like to know how to pass a variable (type=0,1 or 2 for example) when i click on the link. Because in fact, according to on which image i click on, i would like to go on the same page which is a login/password page. but the login/password will be different according to which link i click on.

here a little of my page:
<table bgcolor=&quot;#FFFFFF&quot; width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<font class=&quot;TexteOrangeGras&quot; name=&quot;euro&quot; value=&quot;euro&quot;>
<a href=&quot;/htm/callcenter.html&quot; class=&quot;LienTexteOrangeTitre&quot;>Package EURO<br><br><img src=&quot; border=&quot;0&quot;></a>
</font>
</td>
<td align=&quot;center&quot;>
<font class=&quot;TexteOrangeGras&quot;>
<a href=&quot;/htm/callcenter.html&quot; class=&quot;LienTexteOrangeTitre&quot;>Package S'MILES<br><br><img src=&quot; border=&quot;0&quot;></a>
</font>
</td>
<td align=&quot;center&quot;>
<font class=&quot;TexteOrangeGras&quot;>
<a href=&quot;/htm/callcenter.html&quot; class=&quot;LienTexteOrangeTitre&quot;>Vols OFFLINE<br><br><img src=&quot; border=&quot;0&quot;></a>
</font>
</td>
</tr>
</table>
 
If you're interested in passing a flag of sorts, rather than href-ing (word?) to &quot;/htm/callcenter.html&quot;, change the hrefs to &quot;/htm/callcenter.html?flag=0&quot; or &quot;/htm/callcenter.html?flag=1&quot; or &quot;/htm/callcenter.html?flag=2&quot; (one for each image tag).

Then, in callcenter.html, get the value of the flag using javascript as such:

Code:
var searchString = this.location.search;
//at this point, searchString will equal, for example:  ?flag=0

searchString = searchString.substring((&quot;?flag=&quot;).length);
//now searchString will equal, for example, 0.

Then, based on searchString, apply the appropriate password.

Of course, that might mean hard-coding passwords into your source code in callcenter.html, but you did not indicate how you might be doing this, so perhaps that is your intention.

Good luck.

--Dave
 
Zekmek,

this is probably one of the most common obstacles developers run into: Logging into a system....however, it seems as thought you want to call a page (namely, the same page the user is currently on) and pass it a variable - in which the value of that variable depends on the link they clicked.

Normally, you would do this as follows:

<a href=&quot;page.php?var1=value1&var3=value3&quot;>Link</a>
<a href=&quot;page2.jsp?var2=value2&var4=value4&quot;>Link</a>

The above two examples illustrate the syntax you'd use. There are a few problems I see with this approach: in your code sample you gave us, you are calling a .HTML page. Usually, you call a page that supports some sort of server-side scripting.... i.e. php, asp/x, jsp, cfm, etc, in which case, you'd use the syntax I described above.

Passing variables to a .html page CAN be done...but it's probably not the approach you want to use. In this case, however, you would need to use JavaScript to parse out the QueryString (the URL recieved) to obtain those values. If the pages don't support server side scripting, though, JavaScript is probably not your answer.

Just out of curiousity, what kind of scripting language are you using to validate and verify user access?
 
...to correct myself from my previous response....

the line stated:

&quot;If the pages don't support server side scripting, though, JavaScript is probably not your answer.&quot;

should read:

&quot;If the pages don't support server side scripting, though, JavaScript is probably your answer.&quot;

- my bad. :p
 
thank you for all this answers ;-)

the user access is scripted in JavaServerPages ... ok that's not important.

here is where i arrived:
first page name index.html
<table bgcolor=&quot;#FFFFFF&quot; width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td align=&quot;center&quot;>
<font class=&quot;TexteOrangeGras&quot; name=&quot;euro&quot; value=&quot;euro&quot;>
<a href=&quot;callcenter.html?type=euros&quot; class=&quot;LienTexteOrangeTitre&quot;>Package EURO<br><br><img src=&quot; border=&quot;0&quot;></a>
</font>
</td>
<td align=&quot;center&quot;>
<font class=&quot;TexteOrangeGras&quot;>
<a href=&quot;callcenter.html?type=smiles&quot; class=&quot;LienTexteOrangeTitre&quot;>Package S'MILES<br><br><img src=&quot; border=&quot;0&quot;></a>
</font>
</td>
<td align=&quot;center&quot;>
<font class=&quot;TexteOrangeGras&quot;>
<a href=&quot;callcenter.html?type=vols&quot; class=&quot;LienTexteOrangeTitre&quot;>Vols OFFLINE<br><br><img src=&quot; border=&quot;0&quot;></a>
</font>
</td>
</tr>
</table>



callcenter.html:
function extractURLParam()
{
var typeString = this.location.search;
typeString = typeString.substring((&quot;?type=&quot;).length);
return typeString;
}

<form action=&quot;test.jsp&quot; >
<tr>
<td colspan=&quot;4&quot; align=&quot;center&quot;>
<INPUT TYPE=&quot;hidden&quot; name=&quot;type&quot; value=javascript:extractURLParam();>
</td>
</tr>
</form>

how can i use the function i have wrote extractURLParam() to give a value to my hidden input ? is the syntax write ? i don't think so...

thanks for your answers.
 
I don't know if your syntax is right wihtout testing, but I do know you can take the string manipulation code (in callCenter.html) out of a function (so that it automatically runs as the page loads and makes typeString global)...

Code:
var typeString = this.location.search;
typeString = typeString.substring((&quot;?type=&quot;).length);

...and then replace your <INPUT... html with:

Code:
<SCRIPT>
document.write(&quot;<INPUT TYPE='hidden' name='type' value='&quot;+typeString+&quot;'>&quot;;
</SCRIPT>

'hope this works for you.

--Dave

P.S., as an alternate solution, you can leave your code pretty much as is, NOT assign a value to the hidden field in the HTML, call extractURLParam() as the BODY-tag's onLoad-event, and rather than return the param from the function, use javascript in that function to set the value of the hidden field. Follow?
 
Zemek,
The following peice of code makes two arrays: one holds the variable names, and the other holds the variable values:

------------------------------------------------------------
QueryString.keys = new Array();
QueryString.values = new Array();

function parseQueryString(){
var query = window.location.search.substring(1);
var pairs = query.split(&quot;&&quot;);

for (var i=0;i<pairs.length;i++)
{
var pos = pairs.indexOf('=');
if (pos >= 0)
{
var argname = pairs.substring(0,pos);
var value = pairs.substring(pos+1);
QueryString.keys[QueryString.keys.length] = argname;
QueryString.values[QueryString.values.length] = value;
}
}
}

function QueryString(key){
var value = null;
for (var i=0;i<QueryString.keys.length;i++)
{
if (QueryString.keys==key)
{
value = QueryString.values;
break;
}
}
return value;
}
------------------------------------------------------------

To get this to work:

1) first call the function parseQueryString( ) to fill the two arrays.

2) then call the function QueryString(&quot;varname&quot;)

QueryString will return the value of the variable specified.

Hope this helps. ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top