Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2006, 03:55 PM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default dynamically generated form

I am a self taught, part time ASP/Database programmer (mostly front ends to let users work in a database that has been simplified). JavaScript is something I am pretty poor at.

I have a challege that I believe needs to be handled in JavaScript, but after a week of puzzling over it I still have no clue. My users are supposed to either select an address (already in the database) or create a new one. This happens on one form and could be any number of lines.

My ASP code creates fields a table of fields along the lines of:
ShippingAddress1 CompanyName1
ShippingAddress2 CompanyName2

I know how to check (using an if x && y) statement to see that both items are not selected. Once. But I need somehow tell the code to check Line 1, then if there is a Line 2 check line 2, if not, the code can stop. This could be ANY number of lines....literally up to the hundreds.

Am I way off my rocker thinking JavaScript could do this? Anyone have any ideas? (even just the right keywords to search for help on would be sooooo very helpful)!

 
Old November 8th, 2006, 12:36 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii SaraJaneQ!!

Since ShippingAddress1, ShippingAddress2.... is generated by your asp code,
you can put the counter field<hidden textbox> ,so that you can know ,number of elements
 needs to be check.

e.g.
if asp code generate 10 Addresses ,then ShippingAddress1,2...10
now
<input type=text name="counter" value=10>
this value must come from the no. of records in the recordset.

now you can easily put ur validation using javascript.
hope this will help you

Cheers :)

vinod
 
Old November 8th, 2006, 11:06 AM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks so much for your answer. Actually, I got that far. I do have a counter. But in doing it that way I get stumped as to how to call the line items. How would I get the numbers to apply to field names. I have been guessing at things like:
document.form.field[topnumber].value
document.form.field+topnumber+.value
document.form.field"+topnumber+".value

nothing seems to work. I feel like I am missing something really simple here, but I have really only used javascript for focus() and very simple validation before.

 
Old November 9th, 2006, 08:27 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii SaraJaneQ!!

Hope this will help you.
Please change select option to as per ur requirment(.ie.textbox,whtever field value)

<script>
function Validate()
{
formName=document.testForm
counterValue=formName.counter.value
if(counterValue>0)
{
    for(i=1;i<=counterValue;i++)
    {
    if(parseInt(document.getElementById("shipOpt"+i).v alue,10)==0)
    {
     alert("Please Select Shipping Address"+i)
     document.getElementById("shipOpt"+i).focus();
     return false;
    }

    if(parseInt(document.getElementById("compOpt"+i).v alue,10)==0)
    {
     alert("Please Select Company Address"+i)
     document.getElementById("compOpt"+i).focus();
          return false;
    }

    }
}

     return true;
}

function formSubmit()
{
if(Validate())
{
alert("formsubmitted")
formName=document.testForm
formName.submit();
}
}
</script>

<form name="testForm" action="submitForm.asp">
<table>

<tr>
<td>ShippingAddress</td>
<td>CompanyName</td>
</tr>

<%
ShippingAddress="<option value=0>SelectShippingAddress</option><option value=1>ShippingAddress1</option><option value=2>ShippingAddress2</option><option value=3>ShippingAddress3</option><option value=4>ShippingAddress4</option><option value=5>ShippingAddress5</option>"

CompanyName="<option value=0>SelectCompanyName</option><option value=1>CompanyName1</option><option value=2>CompanyName2</option><option value=3>CompanyName3</option><option value=4>CompanyName4</option><option value=5>CompanyName5</option>"
counter=10

for i=1 to counter
%>
<tr>
<td><select id="shipOpt<%=i%>" name="shipOpt<%=i%>"><%=ShippingAddress%></select></td>
<td><select id="compOpt<%=i%>" name="compOpt<%=i%>"><%=CompanyName%></select></td>
</tr>
<%next%>
<tr><td colspan=2>
<input type=button onclick="formSubmit()" value="Check">
<input type=hidden name="counter" value=<%=counter%>>
</td></tr>
</table>
</form>

Cheers :)

vinod
 
Old November 9th, 2006, 11:11 AM
Registered User
 
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow! Totally above and beyond, but that helps so very much. Thank you Vinod!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically generated dropdownlist csun ASP.NET 1.0 and 1.1 Basics 3 April 8th, 2008 07:38 AM
How to store the dynamically generated controls ? ramesh1520 ASP.NET 2.0 Basics 0 January 2nd, 2008 10:30 PM
Get ID from Labels that are dynamically generated bekim Javascript How-To 6 February 20th, 2006 04:52 AM
dynamically generated submenus elladi Dreamweaver (all versions) 9 December 24th, 2004 08:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.