473,322 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Need to get a value in a form?

I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.

So for example the section of the page I'm interested in will look like
this.

<form action="asubmitpage.htm" method="post">

<select name="ent" onchange="form.submit();">
<option value="UK">UK</option>
<option selected value="USA">USA</option>
<option value="JAPAN">JAPAN</option>
<option value="UK">UK</option>
</select>

I then want to take the selected value and submit it as a hidden field.

<form action="setpov.htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>

I take it javascript is the easiest way to do this.

Regards

Craig

Jul 23 '05 #1
5 1849
In article <11**********************@g47g2000cwa.googlegroups .com>,
cm*******@yahoo.co.uk enlightened us with...
I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.


Why?
Planning to pass on this value in a series of pages?
If so, javascript is not the best solution. You may want to consider server-
side-scripting.

If you still want to do it this way, just have the hidden field already there
and use JS to fill in the value from the querystring.
http://www.ipwebdesign.net/kaelisSpa..._parseUrl.html

--
--
~kaeli~
She was engaged to a boyfriend with a wooden leg but broke
it off.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Why? Because I need to and if i had to explain why then i'd totally
confuse people!

I looked at your example using Firefox and it didn't work.

Jul 23 '05 #3
cm*******@yahoo.co.uk wrote:
I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.

So for example the section of the page I'm interested in will look like
this.

<form action="asubmitpage.htm" method="post">

<select name="ent" onchange="form.submit();">
<option value="UK">UK</option>
<option selected value="USA">USA</option>
<option value="JAPAN">JAPAN</option>
<option value="UK">UK</option>
</select>

I then want to take the selected value and submit it as a hidden field.

<form action="setpov.htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>

I take it javascript is the easiest way to do this.


Your explanation is very confusing. As far as I can tell, you have two
forms. When an option is selected in one form, you want that form to
submit, then re-load the same page with the selected option as the
default selected.

e.g. if I selected "JAPAN", the form submits and the page loads with
"JAPAN" as the default selected, not "USA".

When the page loads, you want to copy the value of the selected option
to a hidden field in another form. Is that it? Seems unusual, but
you're obviously keen to do it.

The obvious solutions are:

1. Have one form and submit it all in one go, no need for the onchange
submit.

2. When the first form submits, return the selected value in the hidden
field. You say this isn't an option, yet you must be going to
change the default selected option anyway.

Given neither of the above seems appropriate:

3. Have the second form get the value of the selected option when it
submits. Then the first doesn't need to submit at all (submitting
onchange is nasty at any time - the user has to repost the form if
they make a simple slip-up).

4. Have an onload function that gets the value of the selected option
and puts it into the hidden field in the second form.

--
Rob
Jul 23 '05 #4
In article <11**********************@f14g2000cwb.googlegroups .com>,
cm*******@yahoo.co.uk enlightened us with...
Why? Because I need to and if i had to explain why then i'd totally
confuse people!
Explaining things often shows that you're going about things the hard way or
shows complete errors in logic. Which is why we ask.

I looked at your example using Firefox and it didn't work.


Please quote what you are replying to.
And it works in my firefox.
What version are you using and explain "doesn't work". Did you get an error?
It isn't supposed to DO anything except fill in the form with the same values
you already chose. Look at the URL to see that the form was submitted. It's
not fancy. It's a simple example and needs fleshed out with url encoding and
whatnot for production use.

--
--
~kaeli~
Well, aren't we just a flipping ray of sunshine?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #5
cm*******@yahoo.co.uk wrote:
I have a form that has a select list.

A user chooses a value and the page refreshes showing the selected
value in the dropdown box.

So I want to use Javascript to get the selected query from the form.

I then want to pass it as a hidden field.

So for example the section of the page I'm interested in will look like
this.

<form action="asubmitpage.htm" method="post">

<select name="ent" onchange="form.submit();"> ^^^^^^^^^^^^^^^^^^^^^^^^^
Don't. It is likely to make the form unusable without a pointing device
if client-side scripting is even supported. Users don't expect forms to
be submitted when they select a value of of its controls, they expect it
to be submitted when they activate a button control instead.
<option value="UK">UK</option>
<option selected value="USA">USA</option>
<option value="JAPAN">JAPAN</option>
<option value="UK">UK</option>
</select>

I then want to take the selected value and submit it as a hidden field.

<form action="setpov.htm" method="post">
<input type="hidden" name="Entity" value=" this is where i want to fill
this with the selected value ">
</form>
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
<script type="text/javascript">
function setValue(oForm, index, value);
{
var e;
if (oForm
&& (e = oForm.elements)
&& (e = e[index])
&& typeof e.value != "undefined")
{
e.value = value;
}
}

function getSelectedValue(oSelect)
{
if (oSelect)
{
if (oSelect.selectedIndex >= 0)
{
return oSelect.options[oSelect.selectedIndex];
}
else
{
return ""; // or any dummy value
}
}
}
</script>
...
<form action="setpov.htm" method="post">
<div>
<input type="hidden" name="Entity" value="">
<select name="ent"
onchange="setValue(this.form, 'Entity',
getSelectedValue(this));">
[...]
</select>
<input type="submit" ...>
</div>
</form>
I take it javascript is the easiest way to do this.


*Client-side* JS is one way, however not the best one as it will not work
without client-side script support -- so you have to test server-side
anyway, why don't you just evaluate the value of the "ent" name-value pair
already submitted?
PointedEars
--
Set truthfulness above everything else.
When a man lies, he kills a part of the world.
-- Merlin (AFAIK)
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Crystal | last post by:
Ok, I know this sounds weird, but it's really bugging me. I have a few list boxes on my form (basic pick a month, year, state stuff) and you can only choose one value. I need to be able to run a...
2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
8
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
1
by: TopherB | last post by:
Hi, First let me say that my knowledge of HTML and Javascript is fairly limited. But I am stuck in a situation of trying to adapt a website's shopping cart to a new one. Here's the problem, the...
3
by: chifm | last post by:
Hi ALL, I dont know much about php, but have got a long form that i need to split into two pages, i want to have the inputs from the page 1 past to page 2 and all submitted via email at the end. I...
14
by: confusedfusion | last post by:
Not sure how many form submissions that have been lost over the years before I started but the company has a contact form that the required fields when validation fails the error message is going...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.