By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,688 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,688 IT Pros & Developers. It's quick & easy.

JS - Object expected Error...please help

P: 2
hi,

I am going mad........because of this error.....
I have done a simple coding........i am getting this error....
solution may be very simple,,,but i dont know..........can any body help me........

I am writing a function for onchange event in a drop down box, this is saying error.

html code:
[HTML] <tr>
<td>Number Of Bedrooms</td>
<td><select name=bedroom onchange="PopulateTextBox(this);">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
</select>
</tr>
[/HTML]

Javascript code

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2.  
  3. function IsNumeric(strString)
  4.    //  check for valid numeric strings    
  5.    {
  6.    var strValidChars = "0123456789";
  7.    var strChar;
  8.    var blnResult = true;
  9.  
  10.    if (strString.length == 0) return false;
  11.  
  12.    //  test strString consists of valid characters listed above
  13.    for (i = 0; i < strString.length && blnResult == true; i++)
  14.       {
  15.       strChar = strString.charAt(i);
  16.       if (strValidChars.indexOf(strChar) == -1)
  17.          {
  18.          blnResult = false;
  19.          }
  20.       }
  21.    return blnResult;
  22.    }
  23.  
  24. function validate()
  25. {
  26. var str = document.propertyadd.reference_no.value;
  27. var return_val = IsNumeric(str)
  28. if(return_val == false)
  29.     {
  30.         alert("Reference No. not a numeric");
  31.     return false;
  32.     }
  33. else
  34.     {
  35.     return;
  36.     }    
  37. }
  38. function PopulateTextBox(get_obj)
  39. {
  40.     //int get_obj = document.proprtyadd.bedroom_no.value;
  41.     alert(get_obj);
  42.     for (int i=get_obj;i>0;i-- )
  43.     {
  44.         document.write("<tr><td>check here </td></tr>");
  45.  
  46.     }
  47. }
  48.  
  49. </SCRIPT>
any one please help ASAP....................
Feb 9 '07 #1
Share this Question
Share on Google+
6 Replies

acoder
Expert Mod 15k+
P: 16,027
In your PopulateTextBox function, use get_obj.value:
Expand|Select|Wrap|Line Numbers
  1. function PopulateTextBox(get_obj)
  2. {
  3.     int objval = get_obj.value;
  4.     alert(objval); // just a test - remove later
  5.     for (int i=objval;i>0;i-- )
  6.     {
  7.         document.write("<tr><td>check here </td></tr>");    
  8.     }
  9. }
Just one thing: you're writing these rows to the screen, but there's no end table tag. That's another problem as is your isNumeric function, but let's deal with this one by one. Does this solve your problem?
Feb 9 '07 #2

dorinbogdan
Expert 100+
P: 839
I know that JavaScript has not the "int" data type.
It will work if replace:
- "int" by "var" , and
- "alert(get_obj)" by "alert(get_obj.value)"
Feb 9 '07 #3

dorinbogdan
Expert 100+
P: 839
Also , use:
Expand|Select|Wrap|Line Numbers
  1. for (var i=get_obj.value;i>0;i-- )
inside of PopulateTextBox function.
Feb 9 '07 #4

acoder
Expert Mod 15k+
P: 16,027
Thanks, dorinbogdan, for that. When I posted the modified code, I didn't spot those errors. That should solve the errors for the OP.
Feb 9 '07 #5

P: 2
hi,
Thanks for all of your help. The problem was "int"...I changed it and it worked.....Thanks Guys.....


Thanks a lot!!!!!!!!!!!!
Feb 10 '07 #6

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad you got your problem solved.
Feb 10 '07 #7

Post your reply

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