Welcome to WebmasterWorld Guest from 54.167.40.25

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Image call script by using onclick

script, connect, php

     
8:09 pm on Nov 6, 2013 (gmt 0)

New User

joined:Nov 4, 2013
posts: 10
votes: 0


I have a form where you have to inset a date.Im using a script that can auto fill the form with a choosen date.

The form looks like this:

<input type="text" value="<?=date('Ymd');?>" id="from" id="<?php echo $_REQUEST["from"]; ?>" name="displaydate">


The:
<?=date('Ymd');?> 
just show the date of today. If you want to use anyother date you can click on the form and a "drop-down" calendar is showed. Its the code:
<?php echo $_REQUEST["from"]; ?> 
that call the script. The script looks like:

<script>
$(function() {
var dates = $( "#from, #to" ).datepicker({
changeMonth: true,
numberOfMonths: 2,
dateFormat: 'yy-mm-dd',
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>


Now what I need help to, is that I would like to place a small calendar image beside the form. When you click the small image the calendar also "drop-down" just as when you click on the form. I have tried with the code:
<img src='images/calendar.png' onclick="from" style='cursor: pointer; vertical-align: middle;' /> 
but that dont help. Any suggestions?
11:01 pm on Nov 11, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:July 19, 2013
posts:1097
votes: 0


Don't reinvent the wheel, use jQuery instead ;)
[jqueryui.com...]
3:29 pm on Nov 12, 2013 (gmt 0)

New User

joined:Nov 12, 2013
posts: 3
votes: 0


Hi,

Please Try This

<img src='images/calendar.png' id="show_cal" style='cursor: pointer; vertical-align: middle;' />

<script>
$("#show_cal").click(function(){
$("#from").trigger('click');
});
</script>
6:39 pm on Nov 12, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:July 19, 2013
posts:1097
votes: 0


Oh, you are using jQuery... lol... oops, my bad! I didn't even look at the JS, because I was in PHP mode.

I don't have time to dig through the jQuery you have right now, but I'll try to remember to come back to this one later on.
8:15 pm on Nov 13, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:943
votes: 0


You could alternativley look into using the CSS :after pseudo class, which if memory serves has been around long enough to not really need to worry about compatability issues with older browsers.