Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
disabling/enabling a text box as per the change of select value.
Old 02-19-2010, 02:10 AM disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Hi,

As per the title, I am trying to disable a text box disable/enable as per the changing the value of select.

I am trying this function.....Please help.

HTML Code:
function changstatus()
 {
    
        var dd = document.getElementById('inpstate'); var value=dd.options[dd.selectedIndex].value;
       if(document.getElementById('inpstate').value=="sel")
       {
               document.getElementById('inpcity').disabled == "true";
               document.getElementById('inpstate').focus();
          }
        else
        {
               document.getElementById('inpcity').disabled == "false";
               document.getElementById('inpcity').focus();
        }
 }
And here I am calling it like this.

PHP Code:
<select id="inpstate" name="inpstate" class="dropdown1_getlisted_businesstype" bgcolor="#FBF4E6" tabindex="3" onchange="javascript: changstatus();" style="width: 210px;">
                                                        <
option value="sel">
                                                        --------------- 
Select 
                                                        State 
---------------                                                        </option>
                                                        <
option value="Uttar Pradesh">Las Vegas</option>
                                                    </
select
Here's the text box I want to disable and enable....
PHP Code:
<select style="width:210px;" name="inpcity" id="inpcity"  tabindex="4" class="dropdown1_getlisted_businesstype" bgcolor="#FBF4E6">
                                                            <
option value="sel">--------------- Select City ---------------</option

Your help would be highly appreciated.

Thanks
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-19-2010, 02:34 AM Re: disabling/enabling a text box as per the change of select value.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
As I already told you in a previous question, you cannot use the .value property on a select id directly. You have to go through the "options" array.
This is the correct way:
Code:
current_value=document.getElementById('inpcity').options[document.getElementById('inpcity').selectedIndex].value
Or shorter:
Code:
sel=document.getElementById('inpcity')
current_value=sel.options[sel.selectedIndex].value
Just like on the line above the if statement (which something I gave you previously, if I remember right)...
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-19-2010 at 02:36 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-19-2010, 02:36 AM Re: disabling/enabling a text box as per the change of select value.
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Ok 2 things that may help.

Is there meant to be a space ( javascript: cha )when you call it?

also wouldnt it be better to just send the select id in the request?
ie: javascript:changstatus(inpstate);

and then something along the lines of?
function changstatus(controlID)

{
document.controlID.disabled="true";
}


__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 02-19-2010, 03:56 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Thanks a lot for your consideration.

I am trying your suggestions........and let you know the result.

Thanks both of you!!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-19-2010, 04:15 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Quote:
Originally Posted by tripy View Post
As I already told you in a previous question, you cannot use the .value property on a select id directly. You have to go through the "options" array.
This is the correct way:
Code:
current_value=document.getElementById('inpcity').options[document.getElementById('inpcity').selectedIndex].value
Or shorter:
Code:
sel=document.getElementById('inpcity')
current_value=sel.options[sel.selectedIndex].value
Just like on the line above the if statement (which something I gave you previously, if I remember right)...
Thanks tripy,

I am already doing this......as I remembered your suggestions....

here:
var dd = document.getElementById('inpstate'); var value=dd.options[dd.selectedIndex].value;
But this is still not working.....I tried your suggestions.

here:
HTML Code:
function changstat()
 {
    var selt=document.getElementById('inpstate')
    var current_value=selt.options[selt.selectedIndex].value 
        
       if(current_value=="sel")
       {
               document.getElementById('inpcity').disabled == "true";
               document.getElementById('inpstate').focus();
          }
        else
        {
               document.getElementById('inpcity').disabled == "false";
               document.getElementById('inpcity').focus();
        }
 }
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes

Last edited by Isabella_Smith; 02-19-2010 at 04:19 AM..
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-19-2010, 04:22 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Quote:
Originally Posted by lynxus View Post
Ok 2 things that may help.

Is there meant to be a space ( javascript: cha )when you call it?

also wouldnt it be better to just send the select id in the request?
ie: javascript:changstatus(inpstate);

and then something along the lines of?
function changstatus(controlID)

{
document.controlID.disabled="true";
}


I tried your suggestions lynxus, but its still not working.

Thanks for your help though.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-19-2010, 06:05 AM Re: disabling/enabling a text box as per the change of select value.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Thanks tripy,

I am already doing this......as I remembered your suggestions....

here:
var dd = document.getElementById('inpstate'); var value=dd.options[dd.selectedIndex].value;
But this is still not working.....I tried your suggestions.
Yes, but in your original post, you have:
Code:
var dd = document.getElementById('inpstate'); var value=dd.options[dd.selectedIndex].value;
if(document.getElementById('inpstate').value=="sel")
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-19-2010, 06:20 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Yes, but now I tried with this one.....

Quote:
function changstat()
{
var selt=document.getElementById('inpstate')
var current_value=selt.options[selt.selectedIndex].value

if(current_value=="sel")
{
document.getElementById('inpcity').disabled == "true";
document.getElementById('inpstate').focus();
}
else
{
document.getElementById('inpcity').disabled == "false";
document.getElementById('inpcity').focus();
}
}
Is this correct????

Thanks for your help.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-19-2010, 07:19 AM Re: disabling/enabling a text box as per the change of select value.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
It seems correct to me...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-19-2010, 07:26 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
But this is not working.....
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-19-2010, 07:56 AM Re: disabling/enabling a text box as per the change of select value.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
What is the error ?
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-20-2010, 12:37 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
The problem is.........there is no error message................Its just not disabling/enabling it.......Thanks
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Old 02-20-2010, 04:32 AM Re: disabling/enabling a text box as per the change of select value.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Then the function is probably not called.

Looking at your first code, I notice 1 thing:
The first select element have only a name, no id. Meaning that the function will not find it.
And that was indeed it.

I got this to work locally:
HTML Code:
<html>
<body>
<select id="inpstate" 
        name="inpstate"
        id="inpstate"
        class="dropdown1_getlisted_businesstype" 
        bgcolor="#FBF4E6" 
        tabindex="3" 
        onchange="javascript: changstat();" 
        style="width: 210px;">
  <option value="sel">
  --------------- Select State ---------------
  </option>
  <option value="Uttar Pradesh">Las Vegas</option>
</select>  
<br/>
<select style="width:210px;" 
        name="inpcity" 
        id="inpcity"  
        tabindex="4" 
        class="dropdown1_getlisted_businesstype" 
        bgcolor="#FBF4E6">
  <option value="sel">--------------- Select City ---------------</option>  
</select>
<br/>
<script type="text/javascript">
function changstat(){
  var selt=document.getElementById('inpstate')
  var current_value=selt.options[selt.selectedIndex].value
  if(current_value=="sel"){
    alert('disabling inpCity');
    document.getElementById('inpcity').disabled == "true";
    document.getElementById('inpstate').focus();
  }
  else{
    alert('enabling inpCity');
    document.getElementById('inpcity').disabled == "false";
    document.getElementById('inpcity').focus();
  }
}
</script>
</body>
</html>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-22-2010, 02:33 AM Re: disabling/enabling a text box as per the change of select value.
Isabella_Smith's Avatar
Ultra Talker

Posts: 285
Trades: 0
Thanks tripy,

Yes, its working but alert only. not disabling/enabling the inpcity.......so this is still not useful........BTW thanks for your efforts..............I think it won't work.....

Thanks
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
buy all indian salwar Kameez, Sarees and clothes
Isabella_Smith is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to disabling/enabling a text box as per the change of select value.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.71516 seconds with 12 queries