Find Jobs
Hire Freelancers

439896 Simple JavaScript Function - Form Show/Hide Fields

N/A

Đang triển khai
Đã đăng vào hơn 13 năm trước

N/A

Thanh toán khi bàn giao
I need a JavaScript function to show/hide multiple form fields based on a drop-down list selection. The select box options are populated by PHP so I need to be able to select the divs to show in the JavaScript code. Example of form: <select id="country" name"country" onchange="Change(this)"> <option>Please Select</option> <?php foreach ($option as $k) { echo '<option value="'.$k.'">'.$k.'</option>'; } ?> </select> <div id="1" style="display:none"> <label>Name:</label> <input type="text" name="name" /> </div> <div id="2" style="display:none"> <label>Email:</label> <input type="text" name="email" /> </div> <div id="3" style="display:none"> <label>City:</label> <input type="text" name="city" /> </div> The JavaScript code should allow me to select for each option, something like; if option value="" then show() if option value="USA" then show(1,2,3) if option value="Canada" then show(2) if option value="UK" then show(3) ... and so on The numbers inside of () are the div ID's to show. NOTE: You will not be able to modify or change the values of the select list since it is populated from PHP. Also, I need to be able to select "pre-selected" option on page load. Like on page load, load option value UK. This is for when I edit the information the fields show up for that option. I can use PHP to call the value also since it will be a different page. So if could be something like onpageload->select="<?php echo $country; ?>" Please PM Questions or Demos.
Mã dự án: 2185771

Về dự án

1 đề xuất
Dự án từ xa
Hoạt động 12 năm trước

Bạn muốn kiếm tiền?

Lợi ích khi chào giá trên Freelancer

Thiết lập ngân sách và thời gian
Nhận thanh toán cho công việc
Phác thảo đề xuất của bạn
Miễn phí đăng ký và cháo giá cho công việc
Đã trao cho:
Avatar người dùng
i can start right now
$10 USD trong 0 ngày
4,9 (285 nhận xét)
6,8
6,8

Về khách hàng

Cờ của
5,0
60
Thành viên từ thg 11 3, 2006

Xác thực khách hàng

Cảm ơn bạn! Chúng tôi đã gửi email chứa đường link để bạn lấy tín dụng miễn phí.
Đã xảy ra lỗi trong khi gửi email của bạn. Hãy thử lại.
Người Dùng Đã Đăng Ký Tổng Số Việc Đã Đăng
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Đang tải xem trước
Đã cấp quyền truy cập vị trí.
Phiên đăng nhập của bạn đã hết hạn và bạn đã bị đăng xuất. Hãy đăng nhập lại.