Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP 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 December 15th, 2006, 07:17 AM
Authorized User
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can I use onchange in combobox

Hi!
I wondered if someone could help me out.
I have a combo with a couple of options that I want to insert into standard text-fields on a form. Its a kind off "load"-function Im looking for.

Code:
<select name="Name">
 <option value=1>config 1</option>
 <option value=2>config 2</option>
 <option value=3>config 3</option>
</select>

Name: <input name="name" type="text" size="5" value="XXXXX">
Setup: <input name="setup" type="text" size="5" value="YYYYY">
When I change my dropdown(name) to show "config 1", I want several "text"-fields(name, setup etc) to be filled with information from a database. The database-connection I think I can take care off, but not the connection between the dropdown and text-fields. If it can be solved, I wish to have it so that the moment I release the mousebutton the selected "config" shows in my fields. It works with a button too, but I already have a form on the page.

I know that there is java-scripts that can do things like that put I want it in php :)

Thanks in advance!!
/Hylsan

 
Old December 18th, 2006, 12:21 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

hi Hylsan,
Try with this code, i think this will help you.
read the database field from the database separated by comma(,)
and write inside combo value, here i have put 1field1,1field2
hope you will get right answer from this.

<script language="javascript">
<!--//
function loadpick()
{
    if(document.getElementById("cmbname").selectedInde x==0){
    document.getElementById("cmbname").selectedIndex=1
    }
    var where_is_mytool=document.getElementById("cmbname") .value;
    var mytool_array=where_is_mytool.split(",");
    document.form1.txtname.value=mytool_array[0]
    document.form1.txtsetup.value=mytool_array[1]
}
//-->
</script>
<form name="form1" method="post">
<select name="cmbname" id="cmbname" onchange="javascript:loadpick()">
 <option value=>select</option>
 <option value="1field1,1field2">config 1</option>
 <option value="2field1,2field2">config 2</option>
 <option value="3field1,3field2">config 3</option>
</select>

Name: <input name="txtname" type="text" size="25" value="XXXXX">
Setup: <input name="txtsetup" type="text" size="25" value="YYYYY">
</form>


surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
 
Old December 18th, 2006, 08:20 AM
Authorized User
 
Join Date: Dec 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was hoping for a non-java soulution but, ok...it kinda worked.

Still open for sugestions regarding doing this in php tho.

thanks
/Hylsan






Similar Threads
Thread Thread Starter Forum Replies Last Post
onChange event mcinar HTML Code Clinic 3 May 24th, 2007 08:46 PM
Event:OnChange catchrohith Classic ASP Basics 0 November 3rd, 2006 12:52 AM
"onchange" not fired fskilnik Dreamweaver (all versions) 2 January 2nd, 2006 05:23 PM
'onChange' crmpicco Javascript How-To 2 January 28th, 2005 05:37 AM
Onchange listbox Varg_88 JSP Basics 1 June 16th, 2004 07:45 AM





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