473,399 Members | 3,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,399 software developers and data experts.

onclick if/else how to?

Hello, I am new to the forums and I have looked for solutions to this issue for two days now and I know it HAS to be something simple.

I am trying to make an onclick for a table cell that will do an if/else... This is for a registration form I am working on.

Basically I have a registration form setup for a LAN party so people who are going can register and pick their seat. In this form the "Pick your seat" field is a link to open a hidden table which is the seating chart on which you can click the seat you want and it puts the seat number into the form for you.

The seating chart is database driven with two fields per entry Seat_Number, Seat_Status and Seat_Name. Using php I created a array of hidden form inputs below the registration page to make a text input with the id of check_(seatnumber) and the value of (whatever that seat number value is)

Looks like this:
Expand|Select|Wrap|Line Numbers
  1. <input name="1" id="check_1" type="hidden" value="open" /><br /><input name="2" id="check_2" type="hidden" value="open" /><br /><input name="3" id="check_3" type="hidden" value="open" /><br /><input name="4" id="check_4" type="hidden" value="open" /><br /><input name="5" id="check_5" type="hidden" value="open" /><br /><input name="6" id="check_6" type="hidden" value="open" /><br /><input name="7" id="check_7" type="hidden" value="open" /><br /><input name="8" id="check_8" type="hidden" value="open" /><br /><input name="9" id="check_9" type="hidden" value="open" /><br /><input name="10" id="check_10" type="hidden" value="open" /><br /><input name="11" id="check_11" type="hidden" value="open" /><br /><input name="12" id="check_12" type="hidden" value="open" /><br /><input name="13" id="check_13" type="hidden" value="reserved" /><br /><input name="14" id="check_14" type="hidden" value="reserved" /><br /><input name="15" id="check_15" type="hidden" value="reserved" /><br /><input name="16" id="check_16" type="hidden" value="reserved" /><br /><input name="17" id="check_17" type="hidden" value="open" /><br /><input name="18" id="check_18" type="hidden" value="open" /><br /><input name="19" id="check_19" type="hidden" value="open" /><br /><input name="20" id="check_20" type="hidden" value="open" /><br /><input name="21" id="check_21" type="hidden" value="open" /><br /><input name="22" id="check_22" type="hidden" value="open" /><br /><input name="23" id="check_23" type="hidden" value="open" /><br /><input name="24" id="check_24" type="hidden" value="open" /><br /><input name="25" id="check_25" type="hidden" value="open" /><br /><input name="26" id="check_26" type="hidden" value="open" /><br /><input name="27" id="check_27" type="hidden" value="open" /><br /><input name="28" id="check_28" type="hidden" value="open" /><br /><input name="29" id="check_29" type="hidden" value="open" /><br /><input name="30" id="check_30" type="hidden" value="open" /><br /><input name="31" id="check_31" type="hidden" value="open" /><br /><input name="32" id="check_32" type="hidden" value="open" /><br /><input name="33" id="check_33" type="hidden" value="open" /><br /><input name="34" id="check_34" type="hidden" value="open" /><br /><input name="35" id="check_35" type="hidden" value="open" /><br /><input name="36" id="check_36" type="hidden" value="open" /><br /><input name="37" id="check_37" type="hidden" value="open" /><br /><input name="38" id="check_38" type="hidden" value="open" /><br /><input name="39" id="check_39" type="hidden" value="open" /><br /><input name="40" id="check_40" type="hidden" value="open" /><br /><input name="41" id="check_41" type="hidden" value="open" /><br /><input name="42" id="check_42" type="hidden" value="open" /><br /><input name="43" id="check_43" type="hidden" value="open" /><br /><input name="44" id="check_44" type="hidden" value="open" /><br /><input name="45" id="check_45" type="hidden" value="open" /><br /><input name="46" id="check_46" type="hidden" value="open" /><br /><input name="47" id="check_47" type="hidden" value="open" /><br /><input name="48" id="check_48" type="hidden" value="open" /><br /><input name="49" id="check_49" type="hidden" value="open" /><br /><input name="50" id="check_50" type="hidden" value="open" /><br /><input name="51" id="check_51" type="hidden" value="open" /><br /><input name="52" id="check_52" type="hidden" value="open" /><br /><input name="53" id="check_53" type="hidden" value="open" /><br /><input name="54" id="check_54" type="hidden" value="open" /><br /><input name="55" id="check_55" type="hidden" value="open" /><br /><input name="56" id="check_56" type="hidden" value="reserved" /><br /><input name="57" id="check_57" type="hidden" value="open" /><br /><input name="58" id="check_58" type="hidden" value="open" /><br /><input name="59" id="check_59" type="hidden" value="open" /><br /><input name="60" id="check_60" type="hidden" value="open" /><br /><input name="61" id="check_61" type="hidden" value="open" /><br /><input name="62" id="check_62" type="hidden" value="open" /><br /><input name="63" id="check_63" type="hidden" value="open" /><br /><input name="64" id="check_64" type="hidden" value="open" /><br /><input name="65" id="check_65" type="hidden" value="reserved" /><br /><input name="66" id="check_66" type="hidden" value="open" /><br /><input name="67" id="check_67" type="hidden" value="open" /><br /><input name="68" id="check_68" type="hidden" value="open" /><br /><input name="69" id="check_69" type="hidden" value="open" /><br /><input name="70" id="check_70" type="hidden" value="open" /><br /><input name="71" id="check_71" type="hidden" value="open" /><br /><input name="72" id="check_72" type="hidden" value="open" /><br /><input name="73" id="check_73" type="hidden" value="open" /><br /><input name="74" id="check_74" type="hidden" value="open" /><br /><input name="207" id="check_207" type="hidden" value="staff" /><br /><input name="206" id="check_206" type="hidden" value="staff" /><br /><input name="200" id="check_200" type="hidden" value="staff" /><br /><input name="201" id="check_201" type="hidden" value="staff" /><br /><input name="202" id="check_202" type="hidden" value="staff" /><br /><input name="203" id="check_203" type="hidden" value="staff" /><br /><input name="204" id="check_204" type="hidden" value="staff" /><br /><input name="205" id="check_205" type="hidden" value="staff" /><br /></div>
ok.. So normally you can click on a table element and choose your seat with this code...
Expand|Select|Wrap|Line Numbers
  1. <td width="36" height="36" onclick="document.getElementById('seat').value = 67;return hs.close(this);" id="s67" onmouseover="changeMe(this,'active',name67), TagToTip('showName')" onmouseout="changeMe(this,seat67,''), UnTip()">&nbsp;</td>
which works great and puts 67 into the form text input with the "id" of "seat"

Because you can click on any seat with the above code it allows you to choose a seat that is already reserved. I am trying to use an if/else statement below to check the array of seatnumbers - seatstatus input boxes and take the appropriate action.... Here is the code..
Expand|Select|Wrap|Line Numbers
  1. onclick="if(document.getElementById('check_65').value = 'open') { document.getElementById('seat').value = 65;return hs.close(this);} else {alert( 'This seat is already reserved!' ) }"
But it does not work at all.. It lets you choose the seat if it is reserved or not... I can reverse this and have it be as follows:
Expand|Select|Wrap|Line Numbers
  1. onclick="if(document.getElementById('check_65').value = 'reserved') {alert( 'This seat is already reserved!' ) }" else { document.getElementById('seat').value = 65;return hs.close(this);}
and all it does is give the alert message no matter if its open or reserved...

I am at my wits end on this and I am rather a n00b to javascripting and such so.. Can someone help me please... pretty please with c++ on top?
Dec 15 '08 #1
4 1717
acoder
16,027 Expert Mod 8TB
Hi, welcome to Bytes.

The solution in this case is quite simple. Use double equals:
Expand|Select|Wrap|Line Numbers
  1. if(document.getElementById('check_65').value == 'open') ...
Using a single equal for comparison would set it rather than compare, so it'd always be true.
Dec 15 '08 #2
@acoder
AWESOME!!!! Thank you.... I knew it HAD to be simple.. my code was sound.. other than a simple little = lol.. nice... Thank you again..

The simplest things can make you pull your hair out...
Dec 15 '08 #3
acoder
16,027 Expert Mod 8TB
You're welcome, of course. Glad to help. Should you have any further questions, post back and we'll see what we can do to help.
Dec 15 '08 #4
I will definitely be around I'm sure.. I already used some code from other posts to spice things up on the site... Thanks!!
Dec 15 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to...
8
by: KS | last post by:
Just to show some code to show the consept. <img id="date" onclick="javascript:show_calendar();" src="/PlexSysWeb/images/show-calendar.gif" width=20 height=18 border=0> What i want the...
2
by: Peter | last post by:
I would like to use code like the following: this.onclick = function(e) { alert("I'm in the onclick handler"); } But I do not want to wipe out any existing onclick event code. I want to do...
17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
5
by: johnsuth | last post by:
I want to produce a trivial demonstration of dynamic modification. I thought that pressing a button might change its color. I studied O'Reillys books and successfully created the button with a...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
5
by: neousr | last post by:
I resolved my previous problems setting the class for buttons.. I need to write an element.SetAttribute('class','myclass') and a element.SetAttribute('className','myclass') for in order to make...
4
by: Amy | last post by:
I need some help. I have this table with alternate row colors. Class gray and class white. I have javascript that do highlight when mouseover row ... and onclick to select row and highlight it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.