473,396 Members | 2,004 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,396 software developers and data experts.

php generated html needs simple javascript function, yet my javascriptsux

mk
Greetings all - im new to this newsgroup so pls dont flame me :p
I need some help! Please view the html below in a browser. Or goto this
url -http://firebrain.co.uk/java-problem.htm

(Assuming you have seen the rendered code)
Basically I need the X buttons to change all the values of each textbox
to zero either in the col or row depending on which button is clicked.

Function summery:
If you click on a X button on the right hand side of the table it resets
all the textboxes in that row. And if you click one of the X buttons
along the base of the table it will reset all the textfields in the column.

I hope the way I named my fields can be for>looped in javascript :)

If you have not seen the HTML in a browser yet please do so because im
sure there is a very easy solution to my problem.

Please please please - this is for a client and im running low on time
Any help would be much appreciated! Any questions just ask

Please reply to this message or (preferably) send me an email to
ja********@firebrain.co.uk

Thank you

--------------------------------------

<form name='availability'>
<p><table cellpadding=3>
<tr>
<td rowspan=2 valign=bottom id='greybg'><b>Dates</b></td>
<td colspan=5 id='purpbg'><b>Building One</b></td>
<td colspan=3 id='purp2bg'><b>Building Two</b></td>
</tr>

<tr>
<td id='purpbg' valign=top style='font-size:7pt;'>Studio Apartment</td>
<td id='purpbg' valign=top style='font-size:7pt;'>Executive Studio
Apartment</td>
<td id='purpbg' valign=top style='font-size:7pt;'>One Bedroom Apartment</td>
<td id='purpbg' valign=top style='font-size:7pt;'>Executive One Bedroom
Apartment</td>
<td id='purpbg' valign=top style='font-size:7pt;'>Two Bedroom Apartment</td>
<td id='purp2bg' valign=top style='font-size:7pt;'>One Bedroom
Apartment</td>
<td id='purp2bg' valign=top style='font-size:7pt;'>Two Bedroom
Apartment</td>
<td id='purp2bg' valign=top style='font-size:7pt;'>Executive Two Bedroom
Apartment</td>

<td id='greybg'><b>Close Out</b></td>
</tr>
<tr>
<td id='r2'><small><b>2006-07-27</b><br>Thursday 27th, July
2006</small></td>
<td id='r2' align=center>
<input name='slots[2006-07-27][1]' type='text' value='1' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-27][2]' type='text' value='1' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-27][3]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>

<input name='slots[2006-07-27][4]' type='text' value='1' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-27][5]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-27][6]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-27][7]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-27][8]' type='text' value='0' size=2>
</td>
<td id='r3' align=center>
<input name='close[2006-07-27]' type='button' value='X' size=2>
</td>

</tr>
<tr>
<td id='r1'><small><b>2006-07-28</b><br>Friday 28th, July 2006</small></td>
<td id='r1' align=center>
<input name='slots[2006-07-28][1]' type='text' value='1' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-28][2]' type='text' value='1' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-28][3]' type='text' value='1' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-28][4]' type='text' value='0' size=2>
</td>

<td id='r1' align=center>
<input name='slots[2006-07-28][5]' type='text' value='1' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-28][6]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-28][7]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-28][8]' type='text' value='0' size=2>
</td>
<td id='r3' align=center>
<input name='close[2006-07-28]' type='button' value='X' size=2>
</td>
</tr>
<tr>

<td id='r2'><small><b>2006-07-29</b><br>Saturday 29th, July
2006</small></td>
<td id='r2' align=center>
<input name='slots[2006-07-29][1]' type='text' value='1' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][2]' type='text' value='1' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][3]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][4]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][5]' type='text' value='0' size=2>

</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][6]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][7]' type='text' value='0' size=2>
</td>
<td id='r2' align=center>
<input name='slots[2006-07-29][8]' type='text' value='0' size=2>
</td>
<td id='r3' align=center>
<input name='close[2006-07-29]' type='button' value='X' size=2>
</td>
</tr>
<tr>
<td id='r1'><small><b>2006-07-30</b><br>Sunday 30th, July 2006</small></td>

<td id='r1' align=center>
<input name='slots[2006-07-30][1]' type='text' value='1' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][2]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][3]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][4]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][5]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][6]' type='text' value='0' size=2>

</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][7]' type='text' value='0' size=2>
</td>
<td id='r1' align=center>
<input name='slots[2006-07-30][8]' type='text' value='0' size=2>
</td>
<td id='r3' align=center>
<input name='close[2006-07-30]' type='button' value='X' size=2>
</td>
</tr>
<tr>
<td id='greybg'><b>Close Out</b></td>
<td id='r3' align=center>
<input type='button' name='closeRange[0]' value='X'>
</td>

<td id='r3' align=center>
<input type='button' name='closeRange[1]' value='X'>
</td>
<td id='r3' align=center>
<input type='button' name='closeRange[2]' value='X'>
</td>
<td id='r3' align=center>
<input type='button' name='closeRange[3]' value='X'>
</td>
<td id='r3' align=center>
<input type='button' name='closeRange[4]' value='X'>
</td>
<td id='r3' align=center>
<input type='button' name='closeRange[5]' value='X'>
</td>
<td id='r3' align=center>
<input type='button' name='closeRange[6]' value='X'>

</td>
<td id='r3' align=center>
<input type='button' name='closeRange[7]' value='X'>
</td>
<td id='r3'>&nbsp;</td>
</tr>
<tr><td height=100 id='r1' valign=middle align=center colspan=10><input
type='submit' accesskey='s' name='apply_changes' value='Apply
Changes'></td></tr>
</table>
</form>

Jul 27 '06 #1
5 1683
mk said the following on 7/27/2006 4:46 PM:
Greetings all - im new to this newsgroup so pls dont flame me :p
It is not a person's newness to this group that gets them flamed, it is
the behavior and/or expectations of people that get them flamed.
I need some help! Please view the html below in a browser. Or goto this
url -http://firebrain.co.uk/java-problem.htm
It's not a Java-problem but ok.
(Assuming you have seen the rendered code)
Basically I need the X buttons to change all the values of each textbox
to zero either in the col or row depending on which button is clicked.
Ok, loop through the form, check for the indexOf your identifying string.
Function summery:
If you click on a X button on the right hand side of the table it resets
all the textboxes in that row. And if you click one of the X buttons
along the base of the table it will reset all the textfields in the column.

I hope the way I named my fields can be for>looped in javascript :)
All form elements can be for>looped, irrelevant of the names. Your
naming convention make it simpler, somewhat, but the naming convention
could be better. column1row1 and so on, so that the name tells you the
column and the row it is in.
If you have not seen the HTML in a browser yet please do so because im
sure there is a very easy solution to my problem.
There is, I gave it above. Search the archives on how to do it.
Please please please - this is for a client and im running low on time
Is your client going to pay me for writing the code for the project?
Any help would be much appreciated! Any questions just ask
Please reply to this message or (preferably) send me an email to
ja********@firebrain.co.uk
Don't ask, and definitely don't expect, an email reply. You ask in
Usenet, you get answered in Usenet.

P.S. You only need one function, not two, to do what you want to do.

Here is you a start:

function resetColOrRow(identifier,formRef){
totalElements = formRef.length;
for (i=0;i<totalElements;i++){
if (formRef.elements[i].name.indexOf(identifier) != -1)
formRef.elements[i].value = 0;
}
}

And call it as such:
resetColOrRow('[1]',this.form)
resetColOrRow('[2006-07-29]',this.form)

Where the first parameter to the function call is the unique part of the
element name you want to match.

It can be made more efficient, I just don't feel like it right now. It
should be tested as well.

There is a bug in that code, related to your HTML as much as to my code,
I will leave that as an exercise for you to discover.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 27 '06 #2
mk wrote:
Greetings all - im new to this newsgroup so pls dont flame me :p
I need some help! Please view the html below in a browser. Or goto this
url -http://firebrain.co.uk/java-problem.htm

(Assuming you have seen the rendered code)
Basically I need the X buttons to change all the values of each textbox
to zero either in the col or row depending on which button is clicked.

Function summery:
If you click on a X button on the right hand side of the table it resets
all the textboxes in that row. And if you click one of the X buttons
along the base of the table it will reset all the textfields in the column.

I hope the way I named my fields can be for>looped in javascript :)

If you have not seen the HTML in a browser yet please do so because im
sure there is a very easy solution to my problem.
Randy gave you one algorithm, another is if the button is in the last
cell of a row, clear the row - otherwise clear the column. Very simple
logic that is dependent on your table structure rather than names/ids.

The implementation would be marginally easier if colgroup or col
elements had a nodeList of the TD elements that belonged to them ...
but no such luck.

--
Rob

Jul 28 '06 #3
mk
RobG wrote:
mk wrote:
>>Greetings all - im new to this newsgroup so pls dont flame me :p
I need some help! Please view the html below in a browser. Or goto this
url -http://firebrain.co.uk/java-problem.htm

(Assuming you have seen the rendered code)
Basically I need the X buttons to change all the values of each textbox
to zero either in the col or row depending on which button is clicked.

Function summery:
If you click on a X button on the right hand side of the table it resets
all the textboxes in that row. And if you click one of the X buttons
along the base of the table it will reset all the textfields in the column.

I hope the way I named my fields can be for>looped in javascript :)

If you have not seen the HTML in a browser yet please do so because im
sure there is a very easy solution to my problem.


Randy gave you one algorithm, another is if the button is in the last
cell of a row, clear the row - otherwise clear the column. Very simple
logic that is dependent on your table structure rather than names/ids.

The implementation would be marginally easier if colgroup or col
elements had a nodeList of the TD elements that belonged to them ...
but no such luck.
thanks :)

Jul 28 '06 #4
mk
Randy Webb wrote:
mk said the following on 7/27/2006 4:46 PM:
>Greetings all - im new to this newsgroup so pls dont flame me :p


It is not a person's newness to this group that gets them flamed, it is
the behavior and/or expectations of people that get them flamed.
>I need some help! Please view the html below in a browser. Or goto
this url -http://firebrain.co.uk/java-problem.htm


It's not a Java-problem but ok.
>(Assuming you have seen the rendered code)
Basically I need the X buttons to change all the values of each
textbox to zero either in the col or row depending on which button is
clicked.


Ok, loop through the form, check for the indexOf your identifying string.
>Function summery:
If you click on a X button on the right hand side of the table it
resets all the textboxes in that row. And if you click one of the X
buttons along the base of the table it will reset all the textfields
in the column.

I hope the way I named my fields can be for>looped in javascript :)


All form elements can be for>looped, irrelevant of the names. Your
naming convention make it simpler, somewhat, but the naming convention
could be better. column1row1 and so on, so that the name tells you the
column and the row it is in.
>If you have not seen the HTML in a browser yet please do so because im
sure there is a very easy solution to my problem.


There is, I gave it above. Search the archives on how to do it.
>Please please please - this is for a client and im running low on time


Is your client going to pay me for writing the code for the project?
>Any help would be much appreciated! Any questions just ask
Please reply to this message or (preferably) send me an email to
ja********@firebrain.co.uk


Don't ask, and definitely don't expect, an email reply. You ask in
Usenet, you get answered in Usenet.

P.S. You only need one function, not two, to do what you want to do.

Here is you a start:

function resetColOrRow(identifier,formRef){
totalElements = formRef.length;
for (i=0;i<totalElements;i++){
if (formRef.elements[i].name.indexOf(identifier) != -1)
formRef.elements[i].value = 0;
}
}

And call it as such:
resetColOrRow('[1]',this.form)
resetColOrRow('[2006-07-29]',this.form)

Where the first parameter to the function call is the unique part of the
element name you want to match.

It can be made more efficient, I just don't feel like it right now. It
should be tested as well.

There is a bug in that code, related to your HTML as much as to my code,
I will leave that as an exercise for you to discover.
Thank you

Jul 28 '06 #5
mk
Randy Webb wrote:
mk said the following on 7/27/2006 4:46 PM:
>Greetings all - im new to this newsgroup so pls dont flame me :p


It is not a person's newness to this group that gets them flamed, it is
the behavior and/or expectations of people that get them flamed.
>I need some help! Please view the html below in a browser. Or goto
this url -http://firebrain.co.uk/java-problem.htm


It's not a Java-problem but ok.
>(Assuming you have seen the rendered code)
Basically I need the X buttons to change all the values of each
textbox to zero either in the col or row depending on which button is
clicked.


Ok, loop through the form, check for the indexOf your identifying string.
>Function summery:
If you click on a X button on the right hand side of the table it
resets all the textboxes in that row. And if you click one of the X
buttons along the base of the table it will reset all the textfields
in the column.

I hope the way I named my fields can be for>looped in javascript :)


All form elements can be for>looped, irrelevant of the names. Your
naming convention make it simpler, somewhat, but the naming convention
could be better. column1row1 and so on, so that the name tells you the
column and the row it is in.
>If you have not seen the HTML in a browser yet please do so because im
sure there is a very easy solution to my problem.


There is, I gave it above. Search the archives on how to do it.
>Please please please - this is for a client and im running low on time


Is your client going to pay me for writing the code for the project?
>Any help would be much appreciated! Any questions just ask
Please reply to this message or (preferably) send me an email to
ja********@firebrain.co.uk


Don't ask, and definitely don't expect, an email reply. You ask in
Usenet, you get answered in Usenet.

P.S. You only need one function, not two, to do what you want to do.

Here is you a start:

function resetColOrRow(identifier,formRef){
totalElements = formRef.length;
for (i=0;i<totalElements;i++){
if (formRef.elements[i].name.indexOf(identifier) != -1)
formRef.elements[i].value = 0;
}
}

And call it as such:
resetColOrRow('[1]',this.form)
resetColOrRow('[2006-07-29]',this.form)

Where the first parameter to the function call is the unique part of the
element name you want to match.

It can be made more efficient, I just don't feel like it right now. It
should be tested as well.

There is a bug in that code, related to your HTML as much as to my code,
I will leave that as an exercise for you to discover.
excellent "starter" function - it turned out to do the entire job very
nicely indeed :) you were correct about the html bug(s) - i found there
were 2 - first was the fact i gave the buttons a name in the same format
as the textboxes (therefore the button would change to 0 also lol) and
secondly my naming convention for the bottom row of buttons changed the
col values to the left (i.e. -1) of the reference

everything fixed now and working perfectly here is the final code if
anyone is interested:

<script language="JavaScript">
function resetColOrRow(identifier,formRef){
totalElements = formRef.length;
newVal=prompt("Please enter new value for entire row/col","0");
if(!newVal.match(/^\d+$/)){
alert("Was not a number");
}else if(newVal.length>2){
alert("Number was too long");
}else{
for (i=0;i<totalElements;i++){
if (formRef.elements[i].name.indexOf(identifier) != -1)
formRef.elements[i].value = newVal;
}
}
}
</script>

Thanks again :)

Jul 28 '06 #6

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

Similar topics

14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
9
by: quikquic | last post by:
Suppose I download a html file with javascript in it, for example, <html> <body> <script language="JavaScript"> document.write("Hello"); </script> </body> </html>
0
by: Jimmy Cerra | last post by:
I recently came up with a cool little stylesheet for definition lists. There is a small demostration for the impatient . I hope this helps someone. Here's how I did it. Definition lists are...
12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
1
by: cirillo_curiosone | last post by:
Hi, i'm new to javascript. I started studing it on the web few weeks ago, but still haven't been able to solve one big problem: HOT TO PASS VALUES FROM A SCRIPT VARIABLE TO A CHILD HTML...
2
by: christine.nguyen | last post by:
Hello all, I have a page called test.html. Within test.html I have an iframe whose source is mypage.html. When mypage.html loads, it dynamically creates a javascript element which contains a...
5
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
18
by: bning | last post by:
Hmm this forum really doesn't give you long enough to type in your question before logging you out.. well here goes my second attempt: I'm trying to teach myself javascript with dom scripting and...
5
by: NuberSteve | last post by:
I'm very new to using CSS and also the concept of slices for mouse-overs, and have made my first attempt at using ImageReady to generate slices of a world map. I basically wanted a map that would...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
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
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...
0
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,...

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.