SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get value from 2 fields onChange?

    I'm trying to create a script in which I can set the background color gradient with a colorpicker and are using 2 functions to create this, but... Is it possible to do this within 1 function?

    This is what i have so far:
    Code HTML4Strict:
    From: <input name="backfrom" id="backfrom" class="color" onchange="bcolorFrom(this.color);" style="width:60px;" value=""> 
    To: <input name="backto" id="backto" class="color" onchange="bcolorTo(this.color);" style="width:60px;" value="">

    And the javascript:
    Code JavaScript:
    function bcolorFrom(c){
    	var f = document.getElementById('backto').value;
    	jQuery("#mif").contents().find("body").css("background", '-webkit-gradient(linear,left top,left bottom, color-stop(0,#'+c+'), color-stop(1,#'+f+'))');
    }
    function bcolorTo(c){
    	var f = document.getElementById('backfrom').value;
    	jQuery("#mif").contents().find("body").css("background", '-webkit-gradient(linear,left top,left bottom, color-stop(0,#'+f+'), color-stop(1,#'+c+'))');
    }

    Hoping for help and thanks in advance ;-)

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,192
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Have a look at the following jsFiddle, basically it has a 2 in one event listener that can the difference between backfrom and backto without the need to repeat the event callback.

    http://jsfiddle.net/eDMZM/1/


Bookmarks

Posting Permissions

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