www.webdeveloper.com
Results 1 to 9 of 9

Thread: Select field which depends on input text field

  1. #1
    Join Date
    Apr 2013
    Posts
    5

    Post Select field which depends on input text field

    Hello,
    I was trying to put a simple html code with javascript but i can't find the solution. Following is my basic html code:

    <form name="student" id="student" action="submit.php" method="post" >

    <label>1. Enter Student Roll Number</label>
    <input type="text" name="rollno" id="rollno" />

    <label>2. Choose Subject</label>
    <select name="mysubject" id="mysubject">
    <option value="1">English</option>
    <option value="2">Math</option>
    <option value="3">Science</option>
    ....
    </select>

    <input type="submit" value="Submit" />
    </form>

    I am trying this:
    1. When visitor enter his roll number in field 1, suppose he enter 1
    2. Then subject field automatically changes to English subject for roll no.1 and similarly if visitor enter roll no.2 then subject auto changes to Math. and so on.

    In this way i want visitor a simple way to deal with this form by avoiding selection of subject from dropdown manually. I know this can be possible with javascript, so i need help here.

  2. #2
    Join Date
    Apr 2013
    Posts
    21
    So you want a user to enter a number instead of choosing from a list? Or did I understanded you wrong?
    What part of it are you having problems doing?
    And are you using php?

  3. #3
    Join Date
    Apr 2013
    Posts
    5
    Yes, user just need to enter his roll number in the text box and by some javascript subject automatically selected according to the roll number entered. Basically i want to make a relationship between text box and select box using some javascript.

    And yes i am using php for form submission. Please help me how to do that?

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    one way binding

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Rolls</title>
    <style type="text/css">
    body{color:#000;background-color:#fff;font-family:Georgia,Verdana;font-size:14px;text-align:center;padding-top:100px;}
    input{text-align:center;}
    </style>
    <script type="text/javascript">
    function bindElems(){
    var rn=document.getElementById('rollno'),ms=document.getElementById('mysubject'),opts=ms.options;
    rn.onkeyup=function(){for(var i in opts){if(this.value===opts[i].value){ms.selectedIndex=i;this.blur();break;}else{continue;}}}
    rn.focus();
    }
    window.onload=bindElems;
    </script>
    </head>
    <body>
    <form name="student" id="student" action="submit.php" method="post" >
    <label>1. Enter Student Roll Number</label>
    <input type="text" name="rollno" id="rollno" />
    <label>2. Choose Subject</label>
    <select name="mysubject" id="mysubject">
    <option value="1">English</option>
    <option value="2">Math</option>
    <option value="3">Science</option>
    </select>
    <br /><br />
    <input type="submit" value="Submit" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="Reset" />
    </form>
    </body>
    </html>
    signature under construction

  5. #5
    Join Date
    Apr 2013
    Posts
    5
    Yes! It worked perfectly. Thanks padonak for quick solution. But now there is a problem.

    Suppose if there are 50 roll number and subjects are 3. Then select box will look lengthy if i do this:
    <label>2. Choose Subject</label>
    <select name="mysubject" id="mysubject">
    <option value="1">English</option>
    <option value="2">Math</option>
    <option value="3">Science</option>
    <option value="4">Maths</option>
    <option value="5">English</option>
    ..so..on..
    </select>

    There will be duplications of same option field. So wondering how this can be possible to bind multiple roll number to same subject.

  6. #6
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    you asked a question and got the answer. no one here knows your goals better that you yourself. do you really need this <select> element? it is not clear what are you trying to get as the result. there may be another way to achieve this, if you describe your goal in details
    signature under construction

  7. #7
    Join Date
    Apr 2013
    Posts
    5
    The above html code was an test data to get some idea. Below is my html code with javascript in file .js as included in head:
    <!DOCTYPE html>
    <html>
    <head>
    <script src="http://sms24x7india.com/mobiledata.js" type="text/javascript"></script>
    </head>
    <body>

    <form>
    <label>Enter Mobile No.:</label><br />
    <input type="text" name="txtPhnNumber" id="txtPhnNumber" maxlength="10" >
    <br />

    <input type="button" name="btnshow" id="btnshow" onclick="return PhoneDetails();" >
    <br />

    <div align="center">
    <div id="name" style=" font-weight:bold" align="center">&nbsp;</div>
    <div id="company" style=" font-weight:bold" align="center">&nbsp;</div>
    <div id="idnumber" style=" font-weight:bold" align="center">&nbsp;</div>
    <div id="information" style=" font-weight:bold" align="center">&nbsp;</div>
    </div>

    </form>

    </body>
    </html>

    Live action:
    http://sms24x7india.com/test.html

    My Goal:
    When user enter a 10 digit number in the text field say 9999999999 then a select box will auto-select a service provider according to text field data entered. Similarly another select box below it auto-select the state based on data entered in text field.

    Currently, i can show all the data outside the select box when user enter a 10 digit number in text field and click on button.
    This is the exact live example a website using that i want am trying to do:
    https://www.paytm.com/
    (In this site when you enter 9999999999 in the text field then mobile operator select box auto-select to "Vodafone")

    Any idea, how to do that please?

  8. #8
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,716
    as far as i can suppose, this is not the only text field and select element question. looking into the page source you can see <script src="/js/jquery-1.5.2.min.js"></script> and that makes me think that the answer may be found somewhere in <script src="/js/min/daa327a34ce614eafa7328d45de111c7.js" defer="defer"></script> linked script which full address is _https://www.paytm.com/js/min/daa327a34ce614eafa7328d45de111c7.js
    Last edited by Padonak; 04-26-2013 at 05:55 PM. Reason: bad english, sorry
    signature under construction

  9. #9
    Join Date
    Apr 2013
    Posts
    5
    I tried to find exactly how it is working but no success. I know there is function called in input onchange function "populateoperator" but in .js file, there is no such function. I had also copied the source code here:
    http://sms24x7india.com/paytm.html
    (But its not working)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.11385 seconds
  • Memory Usage 2,928KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (9)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates