Welcome Guest, Not a member yet? Register   Sign In
Pre select a value from dropdown when a link clicked
#1

I'd like some help please. I'm having this link

PHP Code:
<?php echo anchor('contact#apply''Apply for Job'); ?>

in my Careers page /view, which redirects to the Contact, where I have this dropdown menu in my form

PHP Code:
$reasons = array(
            
'request-feedback'  => 'I'd like more information please',
            '
request-a-demo'=> 'I want a demo of your services', 
            '
work-with-us'  => 'I am interested in working for youy company', // * this is the option I'm interested in
);
<?
php echo form_label('Reason for getting in touch with us''reason'); ?>
<?php 
echo form_dropdown('reason'$reasonsnull'class="form-control"'); ?> // * when user applies for job should have the 3rd option pre selected instead of null
<?php echo form_error('reason'); ?>

What I'd like to do is when a user clicks on that link to redirect him to the contact form and have the work-with-us option pre selected, but only in this case, in any other case the default should be the first one.

How can I do this ?

Note: both Careers and Contact pages have this structure

PHP Code:
careers/index // i.e. controller/method
contact/index 
Reply
#2

The #apply part of the URI is not available to PHP, as the browser doesn't send it to the server, so you have to use JavaScript if it is the only indication you have of the need to pre-select this option.

One method of getting around this would be to make the link a submit button on a form to send a post to the server which could be used to indicate that this should be the default. The post could go to the same URL (with the hash/fragment), and you could back it up with the same JavaScript in case someone comes to the page from an outside source (but at least internal users wouldn't have to have JavaScript enabled for the default to be selected).

I found the following answer on StackOverflow informative (in that it includes code examples) and presented in a mildly entertaining style, even though it was added significantly later than the original question:
http://stackoverflow.com/questions/23175...r-27370176
Reply




Theme © iAndrew 2016 - Forum software by © MyBB