• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Combo box problem

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ...
i have this really strange problem with my combo boxes .....
i have this combo box named group ..... now when i put this javascript
if(its.group.value = "Group")
{
alert("group Selectd");
its.group.focus();
return false;
}
it empties by combo box ... the value "select a group " of the combox changes to " " (empty)....y is it so....... plz help .... as i need it on urgent basis ....!
and the other problm that i'm facing is this...
even when in the combo box i'm selecting some other value other than "group" ..still it gives me the alert "Please select a group".... y is it so..?
i'm calling this java script on submit of the form..!!! and my form name is its,group is the name of the combo box
plz help ...and fast...!
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do not get the value of a drop down that way
Do it this way

Eric
 
Mehak Darti
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
noooo but the second problem is yet there .. if I select any thing else ... it still gives me an alert ... i have made a dummy code just to check ... i'm posting it here...pls tell me where am i going wrong ... coz even if i select 1 or 2 ..it gives me the error .."select a group..!"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language = javascript>
function cf(its)
{
var sel = document.its.D1;
var txt = sel.options[sel.selectedIndex].text;
var opt = sel.options[sel.selectedIndex].value;

if(sel = 'group')
{
alert("Select a Group");
return false;
}
}
</script>
</head>
<body>
<form method="POST" name = "its" action="--WEBBOT-SELF--" onSubmit="return cf(this);">
<!--webbot bot="SaveResults" U-File="fpweb:///_private/form_results.txt"
S-Format="TEXT/CSV" S-Label-Fields="TRUE" -->
<p><select size="1" name="D1">
<option>group</option>
<option>1</option>
<option>2</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>

/******************/
I have tried with all the three varaibles.... but i don't know y ..its not reading any other value except group.....
Try selecting any other value and press on submit ... .it will still give the same alert...!!!
plz tell me where am i going wrong..!!!
thanx... and plz rely fast ...it's urgent..!
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ January 27, 2004: Message edited by: Eric Pascarello ]
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First,
if(sel = 'group'). Here sel is an object.You can not compare an object with any variable.
Second,
if(sel = 'group'). Here you have used "=" sign but not "==" sign.This syntax would never compare but it assigns.
Third.
var opt = sel.options[sel.selectedIndex].value;
Here 'opt' value will always be null as you have not assigned anything to it.
You need to modify your statement,
<option>group</option> with <option value="somevalue">group</option>
Here is the complete code.

--------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language = javascript>
function cf(its)
{
var sel = document.its.D1;
var txt = sel.options[sel.selectedIndex].text;
var opt = sel.options[sel.selectedIndex].value;
if(opt == 'group')// OR if(txt == 'group') bcoz both values are same
{
alert("Select a Group");
return false;
}
}
</script>
</head>
<body>
<form method="POST" name = "its" action="--WEBBOT-SELF--" onSubmit="return cf(this);">
<p><select size="1" name="D1">
<option value = "group">group</option>
<option value = "1">1</option>
<option value = "2">2</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
---------------------------
 
Mehak Darti
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no but then still ... when i use this code .. seprately it works... but when i use it this way it doesn't ...
code:

function cf(its)
{
if(its.group.value == 'Select a Group')
{
var sel = document.its.group;
var txt = sel.options[sel.selectedIndex].text;
var opt = sel.options[sel.selectedIndex].value;
if(opt == 'Select a Group')
{
alert("Select a Group");
return false;
}
}
}

The problem is coming due to the IF loop...and i have to use ti coz there are many other feilds that are called in the function cf(its) ....
Plz help...!
 
Mehak Darti
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and this code ... is giving a javascript error ... that group.value is null.....
<P><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language = javascript>
function cf(its)
{
if(its.group.value == 'Select a Group')
{
var sel = document.its.group;
var txt = sel.options[sel.selectedIndex].text;
var opt = sel.options[sel.selectedIndex].value;
if(opt == 'Select a Group')
{
alert("Select a Group");
return false;
}
}
}
</script>
</head>
<body>
<form method="POST" name = "its" action="--WEBBOT-SELF--" onSubmit="return cf(this);">
<select size="1" name="D1">
<option value = "group">group</option>
<option value = "1">1</option>
<option value = "2">2</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"
name="B2"></p>
</form>
</body>
</html>

y is it so..?
 
Mehak Darti
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the code that i'm actually gonna use in my program ... only that instead of D1 i will be using .. group ..
<P><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language = javascript>
function cf(its)
{
if(its.D1.value = 'Select a Group')
{
var sel = document.its.D1;
var txt = sel.options[sel.selectedIndex].text;
var opt = sel.options[sel.selectedIndex].value;
if(opt == 'group')
{

alert("Select a Group");
return false;
}
}

}
</script>
</head>
<body>
<form method="POST" name = "its" action="--WEBBOT-SELF--" onSubmit="return cf(this);">
<select size="1" name="D1">
<option value = "group">group</option>
<option value = "1">1</option>
<option value = "2">2</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"
name="B2"></p>
</form>
</body>
</html>
The error that i'm getting is this....Object Doesn't support this property or method..!
plz it's urgent ... help..!
 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mehak Darti:
This is the code that i'm actually gonna use in my program ... only that instead of D1 i will be using .. group ..
<P><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
<script language = javascript>
function cf(its)
{
if(its.D1.value = 'Select a Group')
{
var sel = document.its.D1;
var txt = sel.options[sel.selectedIndex].text;
var opt = sel.options[sel.selectedIndex].value;
if(opt == 'group')
{

alert("Select a Group");
return false;
}
}

}
</script>
</head>
<body>
<form method="POST" name = "its" action="--WEBBOT-SELF--" onSubmit="return cf(this);">
<select size="1" name="D1">
<option value = "group">group</option>
<option value = "1">1</option>
<option value = "2">2</option>
</select><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset"
name="B2"></p>
</form>
</body>
</html>
The error that i'm getting is this....Object Doesn't support this property or method..!
plz it's urgent ... help..!



NOTE :

if(its.D1.value = 'Select a Group')
(1) Where you havae assigned this value?
(2) You do not have "<option value = "Select a Group">Select a Group</option> " statement in your code.
(3) As I mentioned earliar, use "==" operator for comparison but not "=".
(4) I did not understand why are using this statement?If this statment true, than other will be false and vice versa.
Bcoz if this is true, your code if(opt == 'group') will never be
true and if this is false, than too.In any case your if(opt == 'group') is not going to be true.
[ January 27, 2004: Message edited by: himanshu patel ]
 
Mehak Darti
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx ..... any way ..... but i don't know y it was not working 4 me...any how i have solved it now .... and i didn't know that when ppl say it's urgent u want to help them less .... i thought this was a freindly place to interact...!! Sorry for the trouble...!
 
himanshu patel
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mehak Darti:
i didn't know that when ppl say it's urgent u want to help them less .... i thought this was a freindly place to interact...!! Sorry for the trouble...!


This is a friendly place and every ranchers are benifited.No one is going to pay here for solving your problems.Everyone has his/her own work and everyone's work is urgent.If you say your works is URGENT !!!, it does not mean that people will keep aside their work and first they will solve your problem.If someone voluntarily devotes their valuable time to help others, we should appriciate him/her.Everyone are free to reply at their own time.Mentioning URGENT just annoy others.And it is not advisable to ask for help for a problem which you can solve yourself.If you had just googled it with your problem,you would have got answer yourself.This would save person's precious time.
[ January 29, 2004: Message edited by: himanshu patel ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Give me the excat the you are using that does not work.
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic