473,545 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with onClick and submit()

I'm currently working on a page the redirects to a necessary page by a
drop-down menu. Currently it is only heading to one of the pages. I'm
not quite sure what I'm doing wrong, but I was hoping someone could
look at my code, and let me know what I'm doing wrong.

-- javascript snippit (in <head> ) -----
<script><!--
function doSubmit()
{
//based on the drop-down value submit to appropriate page
if (document.Selec tForm.SelectPag e.value = "CustomForm " &&
document.Select Form.realname.v alue != "" &&
document.Select Form.email.valu e != "" &&
document.Select Form.PhoneNumbe r.value != "")
{
document.Select Form.action = "CustomForms.ph p";
document.Select Form.submit();
}
else if(document.Sel ectForm.SelectP age.value = "CustomRepo rt" &&
document.Select Form.realname.v alue != "" &&
document.Select Form.email.valu e != "" &&
document.Select Form.PhoneNumbe r.value != "")
{
document.Select Form.action = "CustomReports. php";
document.Select Form.submit();
}
else
{
alert ("Not all required fields have been entered")
}
}
//-->
</script>
-- End Javascript snippet in <head> ----
---- Begin Javascript in <form> of html ------
<form action="" method="POST" enctype="multip art/form-data"
name="SelectFor m" target="_self" id="SelectForm" >

<tr>
<th scope="row"><di v align="right">* Selection</div></th>
<td><select name="SelectPag e" size="1" id="SelectPage" >
<option value="CustomFo rm">Custom Form</option>
<option value="CustomRe port">Custom Report</option>
</select></td>
</tr>

</table>

<input name="Submit" type="submit" dir="ltr" lang="en"
Onclick=doSubmi t() value="Submit"/>
</div></form>

--- End Javascript in <form> in html ------

Sep 21 '05 #1
5 1558

mi******@gmail. com wrote:
I'm currently working on a page the redirects to a necessary page by a
drop-down menu. Currently it is only heading to one of the pages. I'm
not quite sure what I'm doing wrong, but I was hoping someone could
look at my code, and let me know what I'm doing wrong.

-- javascript snippit (in <head> ) -----
<script><!--
function doSubmit()
{
//based on the drop-down value submit to appropriate page
if (document.Selec tForm.SelectPag e.value = "CustomForm " && [snip] else if(document.Sel ectForm.SelectP age.value = "CustomRepo rt" &&

[snip]

Correct the use of your operators. Change = to == since you're doing a
comparison not an assignment.

See if this fixes your application.

Sep 21 '05 #2
You should use the onsubmit event to validate a form.

Like this:

<form onsubmit="retur n validate()"

function validate(){
if( elRef.value == "correct value" )
{
return true;
}
else
{
alert("Please update...")
return false;
}
}
http://km0ti0n.blunted.co.uk/

Sep 21 '05 #3
Thank You so much!!! Works great now!!!

Sep 21 '05 #4
Thank You so much!!! It works great!!!

Sep 21 '05 #5
mi******@gmail. com wrote:
Thank You so much!!! Works great now!!!


A common programming practice is to put literals on the left when doing
comparisons. That way if you accidentally have an assignment, you
*will* get an error when the statement is executed.

e.g. in your case:

if (document.Selec tForm.SelectPag e.value = "CustomForm " ...

will assign the string 'customForm' to the value of the select. The
statement will then be evaluated as 'true' [1].

On the other hand:

if ("CustomForm " = document.Select Form.SelectPage .value ...

will *always* generate an error that you will have to track down and fix.

So if you follow the convention of writing:

if ("CustomForm " == document.Select Form.SelectPage .value ...

your bugs will bite sooner rather than later.
1. A small number of browsers under certain conditions will treat the
assignment as a comparison anyway.
--
Rob
Sep 22 '05 #6

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

Similar topics

2
2212
by: DB | last post by:
Hi All Having stared at this all morning and altered various things with no effect other then to exasperate the problem i'm wondering if anyone could take a look at the code below and see why on earth it's failing - I'm getting a "Object doesn't suppport this property or method" Line 32 char 5 when i attempt to change the location, have...
15
2531
by: JR | last post by:
Hi. I hope someone out there who is more versed with JavaScript than I can help me with the following annoying problem. Here's the problem. I have a form with the following layout: Column A Column B Column C data 4 radio buttons more data .... ... ...
6
6080
by: mike | last post by:
I have a page that uses a some javascript and it works fine in IE but fails to work in Firefox. Basically what I'm trying to do is have 3 iframes on a page but only displaying one of them at a time. A button is displayed for the two iframes that are not displayed and when the button is clicked, the corresponding iframe is shown and the other...
3
2019
by: Robert Dell | last post by:
I have a problem comparing strings in an order form i'm writing. I want to give a running total at the bottom of the page and it appears to be working except it doesn't compare correctly (it always adds things up when you didn't select them) so i only added 2 of the items until I got it worked out. here's the page source (you can look at it...
0
1703
by: voidptr | last post by:
I wirte a table inside the div container but i see something weired.. table expands to right when there is no scroll bar on page..I mean there is slight mislalignment. Below is the sample code of the same....there is a slight misalignment in the header and body table. If page scroll bar is there it will be proper but if not then...
1
2555
by: kkuniya | last post by:
Situation : - A form (method : POST, action : itself, onsubmit : alert 'Submit' ) - Got 2 submit button ( 'Save' , 'View') - Got navigation 1|2|3|4 What I want to do : - Once clicked on the navigation page, it will save the page without need to click on 'Save' button. Currently, if i manually clicked on the 'Save' button; it will save the...
3
11414
by: ilia | last post by:
Hi All, I am a newbie in terms of Javascript, I found some code on the net to swap rows in a table using innerHTML, this works fine in Firefox but IE is complaining, after some googling around I found that innerHTML is read only for tables in IE which is a problem, please see my code below. I need urgent help if anyone has an idea or a...
5
2818
by: Rabel | last post by:
I am a flash designer so I dont know a whole lot about the javascript submit buttons (I may not even be describing it right sorry) but here is the code I am using. <IMG name="Checkout" value="Checkout" SRC="imagesButtons/ purchaseButton_r2_c2.jpg" onMouseOver="this.src = 'imagesButtons/ purchaseButton_r2_c2_f2.jpg'" onMouseOut="this.src =...
1
3189
by: Jacqui | last post by:
Hi, I am trying to write a webpage that has a form on it, which gets submitted when a button is pressed, but also has an onclick event which does some DOM manipulation to display a waiting page. The issue that I am facing is that in Safari, a blank screen is being displayed rather than the waiting page. This is only happening if there...
2
3134
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error message as in alert box as " Internet Explorer cannot open the Internet site http://google.citycarrentals.com.au/viewalllocations.php . Operation...
0
7459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7653
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7749
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5965
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4942
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3444
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3439
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1871
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
695
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.