Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

HTML need help on forms

views
     
TSabubin
post Jun 25 2008, 07:01 PM, updated 18y ago

10k Club
********
All Stars
10,429 posts

Joined: Jan 2003



I have 2 fields that I want to combine when user submit the form.

field1 : text (eg user type "euro")
field2 : droplist (eg user selected "bbb")
field3 = field1 + field2

So when user click submit, I want something like this
CODE
http://action.page.com/input.php?field3=eurobbb


I found some codes that say do the above but I tried and it doesn't work.
CODE

<input type="submit" value="Submit"onClick=" document.all.field3.value = document.all.field1.value + document.all.field2.value ">


I still get
CODE

http://action.page.com/input.php?field1=euro&field2=bbb&field3=#


This post has been edited by abubin: Jun 25 2008, 07:02 PM
zBuffer
post Jun 25 2008, 07:21 PM

Getting Started
**
Junior Member
157 posts

Joined: Jan 2003
From: KayEL



Need your complete HTML code for the form or else I don't understand how your DOM looks like.

Your code should basically look like this:
CODE
<form name="myform" action="input.php" method="get">
<input type="text" name="field1" />
<input type="text" name="field2" />
<input type="hidden" name="field3" />
<input type="submit" name="submit" onclick="document.myform.field3.value=document.myform.field1.value+document.myform.field2.value; return true;"/>
</form>


Though I think by exactly according to your specs, it should look like this:
CODE
<form name="myform" action="input.php" method="get">
<input type="text" name="field1" />
<input type="text" name="field2" />
<input type="button" value="Submit" onclick="document.location=document.myform.action+'?field3='+document.myform.field1.value+document.myform.field2.value;"/>
</form>


*pardon my text boxes, I'm lazy to do list boxes.*

This post has been edited by zBuffer: Jun 25 2008, 07:36 PM
TSabubin
post Jun 25 2008, 08:15 PM

10k Club
********
All Stars
10,429 posts

Joined: Jan 2003



thanks!! the code helps. with some editing, i know what to do.

thanks for the quick reply.
TSabubin
post Jun 26 2008, 11:09 PM

10k Club
********
All Stars
10,429 posts

Joined: Jan 2003



aihh...still got some problem.

I have created a function for submitting forms. The function will be called onclick of the graphics button.


Why doesn't document.location works in my javascript file?

I have

document.myform.field1.value = aaa
document.myform.field2.value = bbb
document.myform.field3.value = document.myform.field1.value + document.myform.field2.value

So, when I submit the form "document.myform.submit()", all the three values got submitted. I only want to submit field3. How? I have tried "document.location = 'field3'" but doesn't work.

zBuffer
post Jun 27 2008, 12:43 AM

Getting Started
**
Junior Member
157 posts

Joined: Jan 2003
From: KayEL



Look at my second example. Try it. I'm not sure if it works on IE, but it works on Firefox.
TSabubin
post Jun 27 2008, 03:14 AM

10k Club
********
All Stars
10,429 posts

Joined: Jan 2003



the second example works but will not if I replace the submit button with some graphics button instead.

using <a href="button" onclick="javascript:submitform();"></a>

something like that lah...but of course also got css to define mouseover and so on.

submitform() is defined in submit.js file.
zBuffer
post Jun 27 2008, 03:59 AM

Getting Started
**
Junior Member
157 posts

Joined: Jan 2003
From: KayEL



Note: onclick is already a JavaScript event, I believe placing "javascript:" will be a syntax error.
TSabubin
post Jun 27 2008, 04:48 AM

10k Club
********
All Stars
10,429 posts

Joined: Jan 2003



ah...ok...removed javascript: but still doesn't work. Cause I can't figure out a way not to include document.myform.field1.value and document.myform.field2.value.

Cause document.location doesn't work in my javascript file. Is that document.location command a DOM and not javascript?
PsyCHZZZ
post Jun 27 2008, 09:19 AM

Getting Started
**
Junior Member
115 posts

Joined: Dec 2005
From: Singapore


Hi, I believe you'll need to use document.location.href instead.

Try this example:
CODE
<form name="test">
<input type="text" name="field1" />
<input type="text" name="field2" />
<input type="button" value="Submit" onClick="document.location.href='test.htm?field3='+document.test.field1.value+document.test.field2.value;"/>
</form>


This should work across all browsers.

This post has been edited by PsyCHZZZ: Jun 27 2008, 09:19 AM
wodenus
post Jun 27 2008, 12:26 PM

Tree Octopus
********
All Stars
14,990 posts

Joined: Jan 2003
QUOTE(abubin @ Jun 26 2008, 11:09 PM)
aihh...still got some problem.

I have created a function for submitting forms. The function will be called onclick of the graphics button.
Why doesn't document.location works in my javascript file?

I have

document.myform.field1.value = aaa
document.myform.field2.value = bbb
document.myform.field3.value = document.myform.field1.value + document.myform.field2.value

So, when I submit the form "document.myform.submit()", all the three values got submitted. I only want to submit field3. How? I have tried "document.location = 'field3'" but doesn't work.
*
Why not have the form submit all 3 and then only use one ? also use post instead of get, get is very easy to manipulate.

fyire
post Jun 27 2008, 12:53 PM

Look at all my stars!!
Group Icon
VIP
9,270 posts

Joined: Jan 2003
From: Somewhere out there
instead of trying to hack your own javascript for such types of form submission, ever thought of using an available library instead? such as:
- mootools
- prototype
- jquery

and so on? that'll keep the lower level stuff out of your hair so you can concentrate more on the business requirements instead
TSabubin
post Jun 27 2008, 02:27 PM

10k Club
********
All Stars
10,429 posts

Joined: Jan 2003



"document.location.href" doesn't work in javascript file.

Yeah..only method that works now is as stated by wodenus to post all but only use those that I want.

BTW, which one of the library is better? jquery or mootools? A lot of people seems to be using them.
fyire
post Jun 27 2008, 08:45 PM

Look at all my stars!!
Group Icon
VIP
9,270 posts

Joined: Jan 2003
From: Somewhere out there
QUOTE(abubin @ Jun 27 2008, 02:27 PM)
"document.location.href" doesn't work in javascript file.

Yeah..only method that works now is as stated by wodenus to post all but only use those that I want.

BTW, which one of the library is better? jquery or mootools? A lot of people seems to be using them.
*
jquery is very complete and quite powerful, but I use mootools 'cause its lighter & smaller, and its enough to do what I need.
zBuffer
post Jun 28 2008, 11:55 AM

Getting Started
**
Junior Member
157 posts

Joined: Jan 2003
From: KayEL



DOM is document object model, it is closely related to JavaScript as it (JavaScript) accessed objects based on DOM.

@abubin:
From your response, it seems like my code works on your browser. That means the problem lies in your code, if you don't post your code, you can't get any help.

POST is as easy to manipulate as GET (it is still clear text). I laugh at the web apps people made for competitions relying on POST on such an unsecured manner. What I do is I create a form and POST the scores without playing the game. (or even flooding their database with invalid scores)

IMHO, using a library just for submitting forms is kinda overkill. The decision is still up to you though.


Edit: Ambiguity

This post has been edited by zBuffer: Jun 28 2008, 12:04 PM

 

Change to:
| Lo-Fi Version
0.0494sec    0.33    5 queries    GZIP Disabled
Time is now: 26th November 2025 - 06:29 AM