/    Sign up×
Community /Pin to ProfileBookmark

Information passed to webpage?

I don’t know if this is an HTML or javascript questions, but I’ll try here first.

Is is possible to startup a webpage with different <form> element settings?
For example:

Can I have a <select> option be checked for item 5 for one start condition but have it checked for item 6 with a different link? (Same question for radio buttons, textbox initial values, etc.)

I don’t know what the format would be but I would think it might look like this in the calling HTML file:
<a href=”somesite” selection=5>Some Site</a> People
where another link to same site would look like:
<a href=”somesite” selection=’6′>Some Site</a> Animals

I know that I can direct the site to appear to start at a differnt place by using the <a name=”namePosition”>xxx</a>
and link via <a name=”somesite#namePosition”>xxx</a>
but this is not the same as what I would like to do.

? Bottom line is this: Can I call the same website with different initial parameter set-up conditions or do I need to have multiple copies of the website with the different initial conditions?

to post a comment
HTML

13 Comments(s)

Copy linkTweet thisAlerts:
@FireCracker37Aug 18.2006 — I haven't tested this, but it seems to me it would work, we used to use this for old school password saving way back in the day.

Call your url like this: http://www.mysite.com/theform.html?elementname=value&otherelement=value

Of course where elementname or otherelement name is, you use the setting for your name attribute in the form field, and for value you assign the value you want selected, displayed, checked, etc.

Hope this helps ?
Copy linkTweet thisAlerts:
@JMRKERauthorAug 18.2006 — Thanks a lot FireCraker37. It's a start so I'll give it a try.
Copy linkTweet thisAlerts:
@JMRKERauthorAug 18.2006 — OK, here is what I have tried, but is not quite working yet. :o

Here is the page I am calling (file is 'test.html'):
[code=php]
<html>
<head>
<title>Test HTML for setting changes</title>
</head>
<body>
<h2>Test of setting changes</h2>
<select id="select1" name="select1">
<option value="" selected></option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>

<option value="5">Option 5</option>
</select><br />
In original file the initial selection
is blank.
</body>
</html>
[/code]


Here is the page I am calling from (file is 'test.htm'):
[code=php]
<html>
<head>
<title>Test HTML for calling and setting changes</title>
</head>
<body>
<h2>Test of setting changes</h2>
<a href="test.html">Regular Call of routine with blank selected</a>
<br /><a href="test.html?select1.options[3].selected">Regular call with 3 set.</a>
<br /><a href="test.html?select1.options[5].selected">Regular call with 5 set.</a>
</body>
</html>[/code]


I also tried:
[code=php]
<br /><a href="test.html?select1.options[3].selected=true">Regular call with 3
[/code]

and
[code=php]
<br /><a href="test.html?document.select1.options[3].selected">Regular call with 3
[/code]

and
[code=php]
<br /><a href="test.html?document.getElementById('select1').options[3].selected">Regular call with 3
[/code]


but none work. I don't get any errors (good), but I don't get any change (bad).

Does anyone have a different suggestion? ?
Copy linkTweet thisAlerts:
@FireCracker37Aug 19.2006 — try doing it like this:
[code=php]
<a href="test.html?select1=3">Regular Call With 3</a>
[/code]
Copy linkTweet thisAlerts:
@JMRKERauthorAug 19.2006 — Nope, any other ideas? Thanks for the attempt FireCracker37.

Results: All links go to site correctly, but display as if all reset to blank when site is first opened.

I'm willing to try anything you (collective you) can think of!
Copy linkTweet thisAlerts:
@ray326Aug 19.2006 — You have to parse the query string in the URL then set the select accordingly. It won't do it automagically.
Copy linkTweet thisAlerts:
@JMRKERauthorAug 19.2006 — OK, here's my attempt to parse the URL information.

Still no errors, but it still doesn't work. ?

I changed the calling routine from that posted before (test.htm):
[code=php]
<html>
<head>
<title>Test HTML for calling and setting changes</title>
</head>
<body>
<h2>Test of setting changes</h2>
<a href="test.html">Regular Call of routine with blank selected</a>
<br /><a href="test.html?select1=3">Regular call with 3 set.</a>
<br /><a href="test.html?select1=5">Regular call with 5 set.</a>
</body>
</html>
[/code]

and have changed the script being called to this (test.html):
[code=php]
<html>
<head>
<title>Test HTML for setting changes</title>
<script type="text/javascript">
<!--
// get selection value to use
sel = window.location.search.substring(1,window.location.search.length);
var tmp = sel.split("="); var selID = tmp[0]; var selValue = tmp[1];
alert(sel+"n"+selID+"n"+selValue); // test alert message

// write document and table headers
onloadstr = (sel == "")?" onLoad=document.getElementById(selID).options[selValue].selected;":"";
//-->
</script>

</head>
<body>
<h2>Test of setting changes</h2>
<select id="select1" name="select1">
<option value=""></option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>

<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
</select><br />
In original file the initial selection is blank.
</body>
</html>
[/code]


The <select> options are not being set to #3 or #5 when called. They always display the 1st option (blank)

I have found that I get an 'undefined' value in the test alert message for the calling link when the option is not defined as with the "?select1=3" or "=5" so I may try using "?select=0" for the blank entry in the future if I can get the other links to work.

Does it look like I have put the commands in the right order or position? Do I need to move the parse routine to within the <BODY> segment instead of the <HEAD>? Do I need to use a 'document.write()' instead of hard coding the selection box?

So many questions ...

I'll keep trying any suggested changes. Thanks again.
Copy linkTweet thisAlerts:
@virtualdAug 19.2006 — Do you have access to a server-side language such as PHP? It makes it incredibly easy to work with variables...
[CODE]
<?php
if (isset($_GET['varname']))
$varname = $_GET['varname'];
else
$varname = "";

echo $varname;
?>
[/CODE]

Thats just an example of how to echo out a variable passed in.. Theres a lot more powerful things you could do, and it would be a lot more reliable than using javascript. The best part is, that it wouldn't rely on the browser having javascript on either.
Copy linkTweet thisAlerts:
@ray326Aug 19.2006 — <body onload="setform()">

Then code your stuff in the setform() function in the head.

And, yes, the right way to do this is on the server if you have that option. It's not trivial but it's very easy.
Copy linkTweet thisAlerts:
@JMRKERauthorAug 20.2006 — :mad: Nope, I don't have server-side access.


:o Wish I did.

I'll try the <body onLoad="setform()"> and report back with success or failure.

Is it possible to set the <select> option in the onLoad= function before the <select> has been defined within the body?

If not, maybe I can't do this at all! :eek:

If yes, then like the Terminator: "I'll be back!" ?
Copy linkTweet thisAlerts:
@ray326Aug 20.2006 — You can do it with Javascript but you can't then guarantee it will happen.
Copy linkTweet thisAlerts:
@JMRKERauthorAug 21.2006 — ray326
You can do it with Javascript but you can't then guarantee it will happen.[/QUOTE]

I'm not sure I understand the statement. Are you addressing the number of users who do not enable javascript? If so, I will just let them pick from the options list normally, as if it was not pre-set as I am proposing to do.

My main goal was to pre-set the options in a <select> box, or possibly a radio button list, or initialize a text box based upon where the call to the common routine came from. I could then eliminate 'X' copies of the common script and let the calling program set the options based upon the calling link. Fewer copies of the script to maintain (and therefore less for me to screw-up :o )

Thanks to all for trying to help.
Copy linkTweet thisAlerts:
@ray326Aug 21.2006 — Are you addressing the number of users who do not enable javascript?[/QUOTE]Yes. As long as you have a work around as you do then it's not a problem.
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...